Created
May 23, 2016 19:34
-
-
Save prplmark/cdb1ac061670c7df18b928deae2dcf5c to your computer and use it in GitHub Desktop.
Gulpfile with webpack definePlugin for environments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dude this was very helpful for me I appreciate you sharing it.