Skip to content

Instantly share code, notes, and snippets.

@prplmark
Created May 23, 2016 19:34
Show Gist options
  • Save prplmark/cdb1ac061670c7df18b928deae2dcf5c to your computer and use it in GitHub Desktop.
Save prplmark/cdb1ac061670c7df18b928deae2dcf5c to your computer and use it in GitHub Desktop.
Gulpfile with webpack definePlugin for environments
// Essentials
var gulp = require('gulp');
var webpack = require('webpack'); // Include webpack to add definePlugin
var webpackStream = require('webpack-stream'); // Use webpack-stream to compile
// Utilities
var gutil = require('gulp-util');
var chalk = require('chalk');
var notify = require('gulp-notify');
var livereload = require('gulp-livereload');
// Webpack config
var config = require('./webpack.config.js')
// Global Default Configs
config.watch = true;
config.progress = true;
config.devtool = 'cheap-module-eval-source-map';
config.plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"'
})
];
// Gulp Default Task
gulp.task('default', ['watch', 'webpack']);
// Gulp Webpack Compiler
gulp.task('webpack', function() {
// Run Webpack
return gulp.src('./app/app.js')
.pipe(webpackStream(config)) // Load Webpack config
.on('error', function(error) { // Error reporting
notify().write({
message: error.message
});
this.emit('end'); /* Allow Webpack to continue watching on error */
})
.pipe(gulp.dest('./app/dist/'))
.pipe(notify({ // Notifiy me when the file is built
title: 'Webpack',
message: 'Generated file: <%= file.relative %>',
}))
.pipe(livereload()); // Run livereload
});
// Gulp Watch Setup for LiveReload
gulp.task('watch', function() {
livereload.listen(); // Starts livereload
});
@lenymo
Copy link

lenymo commented Feb 16, 2018

Dude this was very helpful for me I appreciate you sharing it.

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