Skip to content

Instantly share code, notes, and snippets.

@jacek-dargiel
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save jacek-dargiel/59a559c1fb6888727659 to your computer and use it in GitHub Desktop.

Select an option

Save jacek-dargiel/59a559c1fb6888727659 to your computer and use it in GitHub Desktop.
gulp-webpack-build watch runs first time only
// Simplified gulpfile
var gulp = require('gulp'),
watch = require('gulp-watch'),
webpack = require('gulp-webpack-build');
var CONFIG = {
paths: {
build: 'build',
input: {
scripts: [
'js/**/*.js'
]
},
output: {
scripts: './build/js'
}
},
webpack:{
configFile: webpack.config.CONFIG_FILENAME,
webpackConfig: {
useMemoryFs: true
},
webpackOptions:{
debug: true,
watch: true,
watchDelay: 200
}
}
};
gulp.task('watch', function () {
watch(CONFIG.paths.input.scripts, function (vin) {
gulp.src(vin.path)
.pipe(webpack.closest())
.pipe(webpack.configure(CONFIG.webpack.webpackConfig))
.pipe(webpack.overrides(CONFIG.webpack.webpackOptions))
.pipe(webpack.watch(function (err, stats) {
console.log(this.path);
gulp
.src(this.path, { base: this.base })
.pipe(webpack.proxy(err, stats))
.pipe(webpack.format({ verbose: true }))
.pipe(gulp.dest(CONFIG.paths.output.scripts, { base: CONFIG.paths.output.scripts}));
}));
});
});
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: {
codebase: './js/main.js',
offer: './js/offer.js'
},
output: {
filename: '[name].js'
},
resolve: {
root: [path.join(__dirname, 'bower_components')]
},
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
)
],
devtool: '#source-map',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment