[gulp進(jìn)階] gulpfile 發(fā)布配置(1) -- browserify 用法
公司項(xiàng)目用gulp
蠻多的腌乡,根據(jù)自己平時(shí)的一些積累和收集的淺薄知識(shí)欺旧,為各位介紹平時(shí)項(xiàng)目經(jīng)常使用的gulpfile
配置
const
gulp = require('gulp'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
cssnano = require('gulp-cssnano'),
concat = require('gulp-concat'),
browserify = require('browserify'),
source = require('vinyl-source-stream');
gulp.task('convertJS', () =>
gulp.src('static/js/*.js')
.pipe(babel({ presets: ['es2015'] }))
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
);
gulp.task('convertCSS', () =>
gulp.src('static/css/*.css')
.pipe(concat('static.css'))
.pipe(cssnano())
.pipe(rename((p => ath) { path.basename += '.min'; }))
.pipe(gulp.dest('dist/css'))
);
gulp.task('watch', () => {
gulp.watch('static/css/*.css', ['convertCSS']);
gulp.watch('static/js/*.js', ['convertJS', 'browserify']);
});
gulp.task("browserify", () => {
var b = browserify({
entries: "dist/js/app.js"
});
return b.bundle()
.pipe(source("bundle.js"))
.pipe(gulp.dest("dist/js"));
});
gulp.task('start', ['convertJS', 'convertCSS', 'browserify', 'watch']);
覺(jué)得我的文章能幫到各位的 可以到gitbub star一下 gulp-awesome-tasks
感謝各位的閱讀澎嚣。ps:歡迎轉(zhuǎn)載瓶摆,不用署名刊愚,就說(shuō)你寫的弟头。
以上吩抓。