Skip to content

Instantly share code, notes, and snippets.

@astericky
Created March 3, 2017 12:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astericky/0dac3355c4880cb4f7cb10c23972814a to your computer and use it in GitHub Desktop.
Save astericky/0dac3355c4880cb4f7cb10c23972814a to your computer and use it in GitHub Desktop.
Webpack 2 Config Example
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const VENDOR_LIBS = [
'react', 'react-dom', 'react-router', 'react-redux', 'redux', 'redux-thunk', 'lodash'
]
module.exports = {
context: `${__dirname}/src`,
entry: {
bundle: './js/index.jsx',
vendor: VENDOR_LIBS
},
output: {
path: `${__dirname}/public`,
filename: '[name].[chunkhash].js',
},
devtool: 'inline-source-map',
devServer: {
contentBase: `${__dirname}/src/`,
publicPath: '/',
},
module: {
rules: [
{
test: /\.jsx?$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
sourceMap: true,
localIdentName: '[path]--[name]-[local]--[hash:base64:5]',
},
}],
}),
},
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
new ExtractTextPlugin('style.css'),
new HtmlWebpackPlugin({
template: './index.html'
}),
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment