猿问

gulp 构建问题~

最近学习 gulp ,在一些教程里,总会把:gulp-rev , gulp-rev-replace , gulp-useref 放在一起。

可是在学习中,遇到了很多问题,

左边的是我目录结构,右边的是 gulpfile.js 。

插件依赖什么的都安装好了,只是写法可能有问题。

如上写法运行后,只是 index.html 文件改变了, index 后面加了一串字符。

https://img1.mukewang.com/5bfa557400017b0b09690562.jpg

index.html 这样写应该没有问题的吧?

https://img3.mukewang.com/5bfa558200016df808190562.jpg

生成的 index 。 别人的 不都是 main.css 和 main.js 中间加了 一行字符串吗? 为什么我的是 index.html 文件,加了字符串。这样 我的 browser-sync 服务器 就启动不了了啊?

但是怎么写呢?? 求指导~


呼唤远方
浏览 525回答 1
1回答

临摹微笑

我自己找了资料解决了这个问题,方法如下:gulp.task("index", function() {    var jsFilter = filter("**/*.js", { restore: true });    var cssFilter = filter("**/*.css", { restore: true });    var indexHtmlFilter = filter(['**/*', '!**/index.html'], { restore: true });    return gulp.src("src/index.html")        .pipe(useref()) // Concatenate with gulp-useref        .pipe(jsFilter)        .pipe(uglify()) // Minify any javascript sources        .pipe(jsFilter.restore)        .pipe(cssFilter)        .pipe(cssmin()) // Minify any CSS sources        .pipe(cssFilter.restore)        .pipe(indexHtmlFilter)        .pipe(rev()) // Rename the concatenated files (but not index.html)        .pipe(indexHtmlFilter.restore)        .pipe(revReplace()) // Substitute in new filenames        .pipe(gulp.dest('dist'));});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答