我的一个.html文件导入/socket.io/socket.io.js,我想硫化这个文件,但是忽略导入socket.io的脚本标记
我编写了以下gulp任务:
// vulcanize HTML files
var vulcanizeHtmlSrc = 'views/**/*.html',
vulcanizeHtmlDst = 'build/views';
gulp.task('vulcanize', function() {
gulp.src(vulcanizeHtmlSrc)
.pipe(vulcanize({
excludes: ['//fonts.googleapis.com/*', '/socket.io/socket.io.js'],
stripExcludes: false
}))
.pipe(gulp.dest(vulcanizeHtmlDst));
});我仍然得到以下错误:
ERROR finding /socket.io/socket.io.js我做错了什么?
发布于 2015-07-14 05:24:20
// vulcanize HTML files
var vulcanizeHtmlSrc = 'views/**/*.html',
vulcanizeHtmlDst = 'build/views';
gulp.task('vulcanize', function() {
gulp.src(vulcanizeHtmlSrc)
.pipe(vulcanize({
excludes: ['//fonts.googleapis.com/*',
'./bower_components/polymer/polymer.html'
],
stripExcludes: false,
inlineScripts: true,
inlineCss: true,
implicitStrip: true,
stripComments: true
}))
// pipe to injectString to add script tags that cause an issue with vulcanize
// e.g. <script src="/socket.io/socket.io.js">
// Error caused if the script is added in index.html itself
// ERROR finding /socket.io/socket.io.js
.pipe(injectString.before('<script class="usesSocket.io">', '<script src="/socket.io/socket.io.js"></script>\n'))
.pipe(gulp.dest(vulcanizeHtmlDst));
});只需将一个类添加到需要script的socket.io.js标记中,并在硫化后使用gulp-inject-string模块插入socket.io.js。这有点烦人。无论哪种方式,硫化仍然会导致很多错误,我建议人们避免使用聚合物(如果正在开发的应用程序即将投入生产),直到它完全稳定并且有更好的文档。
发布于 2015-12-01 13:56:37
如果您希望将socket.io脚本保存在原始源代码中,您也可以删除这些脚本,然后按@Torcellite的建议将脚本注入其中。我使用开始和结束注释在HTML中标记这个块。
HTML
<!-- gulp:remove -->
<script src="/socket.io/socket.io.js"></script>
<!-- gulp:endremove -->gulp.task
// 1 - remove server scripts for vulcanization
var start_comment = "gulp:remove",
end_comment = "gulp:endremove",
pattern = new RegExp("(\\<!--\\s" + start_comment + "\\s--\\>)(.*\\n)*(\\<!--\\s" + end_comment + "\\s--\\>)", "g");
.pipe(require('gulp-tap')(function(file) {
file.contents = new Buffer(String(file.contents).replace(pattern, ""));
}))
// 2 - pipe vulcanize...
// 3 - pipe injectString back in...https://stackoverflow.com/questions/31378593
复制相似问题