Skip to content

Instantly share code, notes, and snippets.

@rashedInt32
Last active November 27, 2015 12:01
Show Gist options
  • Save rashedInt32/ec7fdd6df37dd3c2daac to your computer and use it in GitHub Desktop.
Save rashedInt32/ec7fdd6df37dd3c2daac to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var less = require('gulp-less');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var gutil = require("gulp-util");
var webpack = require("webpack");
var path = require("path");
var WebpackNotifierPlugin = require('webpack-notifier');
// Error handler
function errorAlert(error){
notify.onError({title: "Gulp Compiled Error", message: "Check your terminal", sound: "Sosumi"})(error);
console.log(error.toString());
this.emit("end");
};
// webpack normal mode config
var config = {
color: true,
progress: true,
watch: true,
devtool: 'eval',
debug: true,
entry: [
path.resolve(__dirname, 'Assets/js/main.js')
],
output: {
path: path.resolve(__dirname, 'Assets/js/'),
filename: 'bundle.js'
},
plugins: [
new WebpackNotifierPlugin({title: 'Webpack'}),
],
resolve: {
extensions: ['', '.js', '.json', '.coffee']
},
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader' },
],
}
};
// webpack production mode config
var config_pro = {
color: true,
progress: true,
//watch: true, // if you want to watch mode for production mode
devtool: 'eval',
debug: true,
entry: [
path.resolve(__dirname, 'Assets/js/main.js')
],
output: {
path: process.env.NODE_ENV === 'production' ? './Assets/js' : './Assets/js',
filename: 'bundle.min.js'
},
resolve: {
extensions: ['', '.js', '.json', '.coffee']
},
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader' },
],
}
};
//gulp webpack task for normal mode
gulp.task('webpack', function() {
webpack(config, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
}));
});
});
// gulp less task
gulp.task('less', function() {
return gulp.src('Assets/less/style.less')
.pipe(plumber({errorHandler: errorAlert}))
.pipe(less())
.pipe(notify({
title: 'Gulp',
subtitle: 'success',
message: 'less task',
sound: "Pop"
}))
.pipe(gulp.dest('Assets/css/'));
});
// watch task
gulp.task('watch', function() {
gulp.watch('Assets/less/*.less', ['less']);
});
// webpack proMode task
gulp.task('proMode', function() {
webpack(config_pro, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
}));
});
});
// default task
gulp.task('default', ['watch', 'less', 'webpack']);
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"gulp": "^3.9.0",
"gulp-less": "^3.0.5",
"gulp-notify": "^2.2.0",
"gulp-plumber": "^1.0.1",
"gulp-util": "^3.0.7",
"gulp-webpack": "^1.5.0",
"webpack": "^1.12.8",
"webpack-notifier": "^1.2.1"
},
"dependencies": {
"node-notifier": "^4.3.1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment