var gulp = require('gulp'),
uglify = require("gulp-uglify");
webpack = require('gulp-webpack'),
var path = require("path");
var pc = {
entry: './src/index',
output: {
path: path.join(__dirname, 'scripts'),
filename: "app.js",
publicPath: '/scripts/'
},
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
}]
}
};
gulp.task("webpack", function(callback) {
var myConfig = Object.create(pc);
// run webpack
webpack(
// configuration
myConfig
, function(err, stats) {
// if(err) throw new gutil.PluginError("webpack", err);
// gutil.log("[webpack]", stats.toString({
// // output options
// }));
callback();
});
});
gulp.task('minify', function () {
gulp.src('scripts/app.js')
.pipe(uglify()) // 要壓縮的js文件
.pipe(gulp.dest('scripts')); //壓縮后的路徑
});
gulp.task('default', ['webpack', 'minify']);
在項(xiàng)目目錄直接 運(yùn)行 gulp 即可(前提你的裝了gulp)