weak-dictionary
Version:
Universal ES6-compatible WeakMap wrapper
72 lines (62 loc) • 2.05 kB
JavaScript
var gulp = require('gulp'),
gutil = require("gulp-util"),
webpack = require("webpack"),
rimraf = require('rimraf'),
runSequence = require('run-sequence'),
webpackConfig = require("./webpack.config.js"),
packageConfig = require('./package.json'),
fs = require('fs-extra');
gulp.task("dist", function(cb) {
runSequence(
'dist:clean',
'dist:package:debug',
'dist:package:release',
'dist:package:latest-entry',
cb);
});
gulp.task("dist:package:latest-entry", function(cb) {
fs.copy("dist/weak-dictionary-" + packageConfig.version + ".js", "dist/latest.js", cb);
});
gulp.task("dist:package:release", function(cb) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.plugins = myConfig.plugins || [];
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("production")
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
myConfig.output.filename = "dist/weak-dictionary-" + packageConfig.version + ".js";
// run webpack
webpack(myConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack:build", err);
gutil.log("[webpack:build]", stats.toString({
colors: true
}));
cb();
});
});
gulp.task("dist:package:debug", function(cb) {
// modify some webpack config options
var myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = "sourcemap";
myDevConfig.debug = true;
myDevConfig.output.filename = "dist/weak-dictionary-" + packageConfig.version + ".debug.js";
// create a single instance of the compiler to allow caching
var devCompiler = webpack(myDevConfig);
// run webpack
devCompiler.run(function(err, stats) {
if (err) throw new gutil.PluginError("webpack:build-dev", err);
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
cb();
});
});
gulp.task("dist:clean", function(cb) {
rimraf('./dist', cb);
});