Skip to content

Instantly share code, notes, and snippets.

@pigoz
Created November 2, 2016 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigoz/f3ead97b369fb006d25a337524c5b304 to your computer and use it in GitHub Desktop.
Save pigoz/f3ead97b369fb006d25a337524c5b304 to your computer and use it in GitHub Desktop.
webpack/gulp integration
const gulp = require('gulp');
const gutil = require('gulp-util');
const livereload = require('gulp-livereload');
const webpack = require('webpack');
const notify = require('node-notifier');
const config = require('../config');
const manifest = require('../manifest');
const webpackConfigDefault = require('../webpack.config');
const webpackConfigTest = require('../webpack.config.test');
const statsConfig = {
colors: true,
chunkModules: false,
};
function handleStats(stats) {
if (stats.hasErrors()) {
gutil.log(stats.toString(statsConfig));
notify.notify({ title: 'webpack', message: 'js error' });
} else {
gutil.log(stats.toString(statsConfig));
notify.notify({ title: 'webpack', message: 'js compiled successfully!' });
}
}
function runWebpack(webpackConfig, done) {
const compiler = webpack(webpackConfig);
const cb = (err, stats) => {
if (err) {
throw err;
}
handleStats(stats);
livereload.changed(config.paths.webpackMainCss);
if (!done.called) {
/* eslint-disable no-param-reassign */
done.called = true;
done();
}
};
if (webpackConfig.watch) {
compiler.watch({}, cb);
} else {
compiler.run(cb);
}
}
gulp.task('webpack', (done) => {
runWebpack(webpackConfigDefault, done);
});
gulp.task('webpack:test', (done) => {
runWebpack(webpackConfigTest, done);
});
gulp.task('webpack-bundle', ['webpack'], () => {
const src = [
config.dst(config.paths.webpackMain),
config.dst(config.paths.webpackMainCss),
];
return gulp.src(src, { base: config.dst() })
.pipe(manifest.write());
});
@pigoz
Copy link
Author

pigoz commented Nov 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment