-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
在网上看到的文章都是用的gulp-rev与gulp-rev-collector但是使用这个有个弊端,无法通过watch后不断的更新,看了下它的基本原理是,会生成一个rev的文件夹存储着json,一个键值对,猜想最后是读入html文件找到匹配的文件替换,这种方式只适合最后build的时候使用,不适合动态的插入script和css
最后我使用的是gulp-hash-filename与gulp-inject
gulp-hash-filename
主要是用来给文件加上hash值,类似于md5
gulp-inject
用来将css,js注入到html中
在小项目使用的时候我是将多个css合并成一个文件的,然后添加上hash的, 目前存在问题的是每次编译的时候不删除dist文件的话会有多个hash文件存在,后期看如何优化
gulp.task('index', ['postcss', 'toes'], () => {
const target = gulp.src('./index.html');
const sources = gulp.src(['./dist/js/**/*.js', './dist/css/**/*.css'], { read: false})
return target.pipe(inject(sources, {
addRootSlash: false,
addPrefix: '.'
}))
.pipe(gulp.dest('./'))
.pipe(notify("inject build success!"));
})插件推荐
gulp-uncss
去除未使用的css
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels