首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >怎样才能让硫化症视而不见socket.io.js?

怎样才能让硫化症视而不见socket.io.js?
EN

Stack Overflow用户
提问于 2015-07-13 08:25:09
回答 2查看 616关注 0票数 3

我的一个.html文件导入/socket.io/socket.io.js,我想硫化这个文件,但是忽略导入socket.io的脚本标记

我编写了以下gulp任务:

代码语言:javascript
复制
// 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));    
});

我仍然得到以下错误:

代码语言:javascript
复制
ERROR finding /socket.io/socket.io.js

我做错了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-14 05:24:20

代码语言:javascript
复制
// 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));
});

只需将一个类添加到需要scriptsocket.io.js标记中,并在硫化后使用gulp-inject-string模块插入socket.io.js。这有点烦人。无论哪种方式,硫化仍然会导致很多错误,我建议人们避免使用聚合物(如果正在开发的应用程序即将投入生产),直到它完全稳定并且有更好的文档。

票数 3
EN

Stack Overflow用户

发布于 2015-12-01 13:56:37

如果您希望将socket.io脚本保存在原始源代码中,您也可以删除这些脚本,然后按@Torcellite的建议将脚本注入其中。我使用开始和结束注释在HTML中标记这个块。

HTML

代码语言:javascript
复制
<!-- gulp:remove -->
<script src="/socket.io/socket.io.js"></script>
<!-- gulp:endremove -->

gulp.task

代码语言:javascript
复制
  // 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...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31378593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档