Skip to content

Instantly share code, notes, and snippets.

@wolever
Last active November 5, 2015 21:39
Show Gist options
  • Save wolever/94105b6bcf68a5fccc90 to your computer and use it in GitHub Desktop.
Save wolever/94105b6bcf68a5fccc90 to your computer and use it in GitHub Desktop.
My Webpack config
// Used to define the asset prefix at runtime
__webpack_require__.p = window.WEBPACK_ASSET_PREFIX || "ERROR-WEBPACK_ASSET_PREFIX-NOT-SET/";
'use strict';
/**
* Use "PROD=1 webpack" to trigger a production build.
*/
var path = require('path');
var webpack = require('webpack');
var shim = './akindi/webpack/shim.js';
var IS_DEV = !process.env.PROD;
var IS_PROD = !IS_DEV;
module.exports = {
cache: true,
// Note: 'eval' if faster but 'source-map' may be better quality?
devtool: IS_DEV && 'eval',
entry: {
// Note: the dummy entrypoint is needed to trigger CommonsChunkPlugin to
// de-dupe the code shared between base-script and the application.
'_dummy_base-script': [shim, './akindi/base-script.js', './akindi/style/base-style.less'],
'script': [shim, './akindi/index.js', './akindi/style/base-style.less'],
'style': [shim, './akindi/style/style.less'],
'browser-version-check': [shim, './akindi/style/browser-version-check.less', './akindi/browser-version-check.js'],
},
output: {
sourcePrefix: '',
path: path.join(__dirname, 'dist'),
filename: '[name].js',
chunkFilename: '[name]-[id].js',
sourceMapFilename: IS_DEV && '[file].map',
},
resolve: {
modulesDirectories: ['./bower_components', './node_modules', '.'],
extensions: ['', '.js', '.es6'],
},
module: {
preLoaders: [
{ test: /\.js$/, loader: 'eslint-loader', exclude: /(node_modules|bower_components)/ },
{ test: /\.es6$/, loader: 'eslint-loader' },
],
loaders: [
{ test: /\.es6$/, loader: 'babel' },
{ test: /\.html$/, loader: 'raw' },
{ test: /\.less$/, loaders: ['style', 'css', 'less'] },
{ test: /\.css$/, loaders: ['style', 'css'] },
{ test: /\.png$/, loader: 'file' },
{ test: /\.woff$/, loader: 'file?prefix=fonts/' },
{ test: /\.ttf$/, loader: 'file?prefix=fonts/' },
{ test: /\.eot$/, loader: 'file?prefix=fonts/' },
{ test: /\.svg$/, loader: 'file?prefix=fonts/' },
{ test: /\.swf$/, loader: 'file' },
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('base-script.js', ['_dummy_base-script', 'script']),
new webpack.DefinePlugin({
AKINDI_BUILD_NUMBER: +(new Date()),
}),
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
),
].concat(IS_PROD? [
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.UglifyJsPlugin({
mangle: false,
compressor: {
warnings: false,
},
}),
] : []),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment