Skip to content

Instantly share code, notes, and snippets.

@duncan60
Created April 21, 2016 01:18
Show Gist options
  • Save duncan60/4ca14047f8fc3b41950998b6b14d8456 to your computer and use it in GitHub Desktop.
Save duncan60/4ca14047f8fc3b41950998b6b14d8456 to your computer and use it in GitHub Desktop.
var Webpack = require('webpack'),
path = require('path'),
util = require('util'),
pkg = require('./package.json'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin');
var nodeModulesPath = path.resolve(__dirname, 'node_modules'),
buildPath = path.resolve(__dirname, 'dist'),
mainPath = path.resolve(__dirname, 'src', 'app', 'app.js'),
cssBundleName = util.format('style.bundle.%s.css', pkg.version),
jsBundleName = util.format('js/app.bundle.%s.js', pkg.version);
process.env.UV_THREADPOOL_SIZE = 100;
var config = {
devtool: 'source-map',
entry: {
app: [mainPath],
vendors: pkg.vendors
},
output: {
path: buildPath,
filename: jsBundleName
},
module: {
loaders: [
{
test: /\.js(x)?$/,
loader: 'babel?stage=0',
exclude: nodeModulesPath
},
{
test: /\.(css|scss)$/,
loader: ExtractTextPlugin.extract('css?sourceMap!sass?sourceMap')
},
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
loader: 'url?limit=8192&name=assets/images/[name].[ext]'
},
{
test : /\.(woff|woff2|ttf|eot|svg)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url?limit=8192&name=assets/fonts/[name].[ext]'
}
]
},
plugins: [
new ExtractTextPlugin(cssBundleName),
new Webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'root.jQuery': 'jquery',
'moment':'moment',
'Cookies':'cookies-js'
}),
new Webpack.optimize.CommonsChunkPlugin('vendors', 'js/vendors.bundle.js', Infinity),
new Webpack.optimize.UglifyJsPlugin({
sourceMap: false,
compress: {
warnings: false
}
}),
new Webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-tw|zh-cn/),
new HtmlWebpackPlugin({
title: pkg.name,
hash: true,
filename: 'index.html',
template: './src/assets/templates/index-template.html'
})
],
resolve: {
modulesDirectories: [
'app',
'node_modules'
],
extensions: ['', '.js', '.jsx', '.css', '.scss']
}
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment