Skip to content

Instantly share code, notes, and snippets.

@jh3y
Last active September 22, 2016 22:59
Show Gist options
  • Save jh3y/2755e9c0a0370a2467c8cd89736891d8 to your computer and use it in GitHub Desktop.
Save jh3y/2755e9c0a0370a2467c8cd89736891d8 to your computer and use it in GitHub Desktop.
Basic webpack configuration
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const path = require('path');
const IS_DIST = (process.argv.indexOf('--dist') !== -1) ? true : false;
const config = {
devServer: {
port: 1987
},
entry: {
app: './src/script/app.js',
/* create a vendor chunk for grabbing vendor resources */
vendor: [
'lodash'
]
/* Create another chunk for a different page etc. */
// app2: './src/script/app2.js'
},
output: {
path: `${__dirname}/public`,
filename: '[name].js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
include: /(src\/script)/,
query: {
presets: [
'es2015'
]
}
},
{
test: /\.styl$/,
include: /(src\/)/,
// loader: 'style-loader!css-loader!postcss-loader!stylus-loader'
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!stylus-loader?paths=src/style')
}
]
},
resolve: {
root: [
path.resolve('./src/script'),
path.resolve('./src/style')
],
extensions: [ '', '.js', '.styl' ]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/markup/index.html',
filename: 'index.html',
chunks: ['vendor', 'app']
}),
new webpack.optimize.CommonsChunkPlugin(
/* chunkName= */'vendor',
/* filename= */'vendor.js'
),
/* Example if we wanted to create a second page */
// new HtmlWebpackPlugin({
// template: './src/markup/index.html',
// chunks: ['app2'],
// filename: 'app.html'
// }),
new ExtractTextPlugin('app.css'),
/* If --dist is present in process opts then minimize bundles */
(IS_DIST) ? new webpack.optimize.UglifyJsPlugin() : function () {}
],
postcss: function () {
return [ autoprefixer ];
}
}
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment