刚开始接触咕嘟咕嘟 - 它再用巨大的。这工作,但在rev.manifest写上本身不具备这两个“风格”,并在其“脚本”。一定会有更好的办法。对? :-)
gulp.task('script', function() {
var scripts = gulp.src('source-js/main.js')
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest());
var manifest = gulp.src('./rev-manifest.json');
return es.merge(scripts, manifest)
.pipe(rev.manifest())
.pipe(gulp.dest('.'))
});
gulp.task('style', function() {
var styles = gulp.src('source-less/style.less')
.pipe(less({compress: true}))
.pipe(rev())
.pipe(gulp.dest());
var manifest = gulp.src('./rev-manifest.json');
return es.merge(styles, manifest)
.pipe(rev.manifest())
.pipe(gulp.dest('.'))
});
gulp.task('watch', function () {
gulp.watch('source-less/**/*.less', ['style']);
gulp.watch('source-js/**.js', ['script']);
});
编辑:与ES努力仍然是情人写的清单:
gulp.task('script', function() {
var scripts = gulp.src('source-js/main.js')
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('assets/js'));
var manifest = gulp.src('./rev-manifest.json');
return es.merge(scripts, manifest)
.pipe(rev.manifest())
.pipe(gulp.dest('.'))
});
gulp.task('style', function() {
var styles = gulp.src('source-less/style.less')
.pipe(less({compress: true}))
.pipe(rev())
.pipe(gulp.dest('assets/css'));
var manifest = gulp.src('./rev-manifest.json');
return es.merge(styles, manifest)
.pipe(rev.manifest())
.pipe(gulp.dest('.'))
});
还有就是直接添加manifest.json
到流,以防止它被覆盖,但有相关gulp#396禁止使用它vinyl-fs#25当前的错误的例子。对于未来的读者,当它的固定:
gulp.task('scripts', function() {
gulp.src('source-js/main.js')
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('assets/js'))
.pipe(gulp.src('./rev-manifest.json'))
.pipe(rev.manifest())
.pipe(gulp.dest('assets'));
});
但现在,你应该使用event-stream这一点。需要注意的是,直到gulp-rev#59合并,它不会工作。
var es = require('event-stream');
gulp.task('scripts', function() {
var scripts = gulp.src('source-js/main.js')
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('assets/js'));
var manifest = gulp.src('./rev-manifest.json');
return es.merge(scripts, manifest)
.pipe(rev.manifest())
.pipe(gulp.dest('.'))
});
你style
任务将遵循相同的模式。所有这一切都假定你manifest.json
会在根目录下。
这里是我的解决方案。
该文件夹结构
└── src
├── images
│ ├── skywalker.jpeg
│ └── space.png
├── js
│ ├── index.js
│ ├── index2.js
│ └── page.js
├── styles
│ ├── index.css
│ ├── index.styl
│ ├── module
│ │ ├── com.css
│ │ └── com.styl
│ └── page.css
└── view
├── index.html
└── page.html
我一饮而尽任务
/**
* production
*/
var jsProductionPipe = lazypipe()
.pipe(jshit)
.pipe(jshit.reporter, 'default')
.pipe(uglify, {
compress: {
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true
}
}),
cssProductionPipe = lazypipe()
.pipe(stylus).pipe(minifyCss);
gulp.task("deploy_js_css", ["deploy_image"], function () {
var manifest = gulp.src(path.join(__dirname, "dist/rev-manifest.json"));
return gulp.src(["src/**/*.styl", "src/**/*.js"])
.pipe(debug({title: '[deploy_js_css]:'}))
.pipe(revReplace({manifest: manifest, replaceInExtensions: ['.js', '.css', '.html', '.hbs', '.styl']}))
.pipe(gulpif('*.styl', cssProductionPipe()))
.pipe(gulpif('*.js', jsProductionPipe()))
.pipe(rev())
.pipe(gulp.dest("dist"))
.pipe(rev.manifest("dist/rev-manifest.json", {
merge: true
}))
.pipe(revDel({ dest: 'dist', oldManifest: path.join(__dirname, "dist/rev-manifest.json") }))
.pipe(gulp.dest("./"));
});
gulp.task("deploy_image", function() {
return gulp.src("src/images/*", {
base: "src/"
})
.pipe(debug({title: '[deploy_image]:'}))
.pipe(imagemin({
progressive: true
}))
.pipe(rev())
.pipe(gulp.dest("dist"))
.pipe(rev.manifest("dist/rev-manifest.json", {
merge: true
}))
.pipe(revDel({ dest: 'dist', oldManifest: path.join(__dirname, "dist/rev-manifest.json") }))
.pipe(gulp.dest("./"));
});
gulp.task('production', ['deploy_image', 'deploy_js_css']);