Last active
August 29, 2015 14:17
-
-
Save sunify/c9a4dee36c0ff8a88d4e to your computer and use it in GitHub Desktop.
My webpack+gulp config
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
var notifier = require('node-notifier'); | |
var gulp = require('gulp'); | |
var g = require('gulp-load-plugins')(); | |
var lr = require('tiny-lr'); | |
var server = lr(); | |
var minimist = require('minimist'); | |
var env = minimist(process.argv.slice(2)); | |
var debug = !!env.debug || !!env.d; | |
var watch = env._[0] === 'watch'; | |
var webpack = require('webpack'); | |
var webpack_cfg = require('./webpack.config.js'); | |
gulp.task('scripts', ['lang'], function(cb) { | |
webpack(webpack_cfg(watch, debug), function(err, stats) { | |
if(stats.compilation.errors.length > 0) { | |
console.log('============================================================'); | |
g.util.log(stats.compilation.errors[0].error.message); | |
console.log('============================================================'); | |
if(watch) { | |
notifier.notify({ | |
title: 'Error', | |
message: stats.compilation.errors[0].error.message, | |
wait: true, | |
open: 'file://' + stats.compilation.errors[0].module.resource | |
}); | |
} | |
} else { | |
g.util.log("[webpack]", stats.toString({ | |
colors: true | |
})); | |
gulp.src('index.php').pipe(g.livereload(server)); | |
} | |
}); | |
}); | |
gulp.task('watch', ['scripts'], function() { | |
server.listen(35729, function(err) { | |
if(err) { | |
console.log(err); | |
} | |
//start watch some tasks here | |
}); | |
}); | |
gulp.task('default', ['scripts', 'images', 'svg', 'sass']); |
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
var webpack = require('webpack'); | |
module.exports = function(watch, debug) { | |
watch = watch === undefined ? false : watch; | |
debug = debug === undefined ? false : debug; | |
return { | |
entry: { | |
app: './src/react/app.js', | |
main: './src/js/legacy.js' | |
}, | |
output: { | |
path: __dirname + '/js', | |
filename: '[name]-built.js' | |
}, | |
resolve: { | |
extensions: ['', '.js', '.js'], | |
modulesDirectories: ['node_modules', 'bower_components', 'src/react'] | |
}, | |
devtool: '#source-map', | |
watch: watch, | |
module: { | |
loaders: [ | |
{test: /\.js$/, exclude: /node_modules/, loader: 'babel'}, | |
{test: require.resolve('react'), loader: 'expose?React'}, | |
{test: require.resolve('immutable'), loader: 'expose?Immutable'} | |
], | |
}, | |
externals: { | |
"jquery": "jQuery" | |
}, | |
plugins: [ | |
debug && new webpack.optimize.UglifyJsPlugin(), | |
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify(debug ? 'development' : 'production') | |
} | |
}), | |
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /ru|es|uk/), | |
new webpack.optimize.CommonsChunkPlugin({ | |
filename: 'common-built.js', | |
minChunks: 2 | |
}), | |
new webpack.ProvidePlugin({ | |
to5Runtime: "imports?global=>{}!exports?global.to5Runtime!babel/runtime" | |
}) | |
], | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment