Created
December 20, 2016 23:12
-
-
Save tremby/1ed5ef73f111dcc6223b6718dd901673 to your computer and use it in GitHub Desktop.
Example webpack configuration
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
import autoprefixer from 'autoprefixer'; | |
import mqpacker from 'css-mqpacker'; | |
import path from 'path'; | |
import webpack from 'webpack'; | |
let srcDir = path.join(__dirname, 'src'); | |
let globalStylesDir = path.join(srcDir, 'scss'); | |
let config = { | |
context: srcDir, | |
debug: true, | |
devServer: { | |
contentBase: 'public', | |
historyApiFallback: true, | |
hot: true, | |
}, | |
devtool: 'eval-source-map', | |
entry: [ | |
'webpack-dev-server/client?http://0.0.0.0:8080', | |
'webpack/hot/only-dev-server', | |
'./index', | |
], | |
module: { | |
loaders: [ | |
{ | |
include: srcDir, | |
loaders: [ | |
'react-hot', | |
'babel', | |
], | |
test: /\.jsx?$/, | |
}, | |
{ | |
include: globalStylesDir, | |
loaders: [ | |
'style', | |
'css?modules&sourceMap&importLoaders=1&localIdentName=[local]', | |
'postcss', | |
'sass?sourceMap', | |
], | |
test: /\.scss$/, | |
}, | |
{ | |
exclude: globalStylesDir, | |
include: srcDir, | |
loaders: [ | |
'style', | |
'css?modules&sourceMap&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]', | |
'postcss', | |
'sass?sourceMap', | |
], | |
test: /\.scss$/, | |
}, | |
{ | |
include: srcDir, | |
loader: 'url?limit=16384', | |
test: /\.(jpg|png|ttf|eot|woff|woff2)$/, | |
}, | |
{ | |
include: srcDir, | |
loader: 'raw', | |
test: /\.svg$/, | |
}, | |
{ | |
loader: 'modernizr-auto', | |
test: /\/\.modernizr-autorc$/, | |
}, | |
], | |
preLoaders: [ | |
{ | |
include: srcDir, | |
loader: 'eslint', | |
test: /\.jsx?$/, | |
}, | |
], | |
}, | |
output: { | |
filename: 'app.js', | |
path: path.join(__dirname, 'build/scripts'), | |
publicPath: 'http://sparkit.dev.tribal.io:8080/scripts', | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin(), | |
], | |
postcss: [ | |
autoprefixer({ | |
browsers: [ | |
'> 1%', | |
'last 2 versions', | |
'ie >= 10', | |
], | |
cascade: false, | |
}), | |
mqpacker(), | |
], | |
resolve: { | |
alias: { | |
modernizr$: path.resolve(__dirname, '.modernizr-autorc'), | |
}, | |
extensions: [ | |
'.jsx', | |
'.js', | |
'', | |
], | |
}, | |
}; | |
if (process.env.NODE_ENV === 'production') { | |
config.devtool = 'source-map'; | |
config.devServer = {}; | |
config.plugins = [ | |
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify('production'), | |
}, | |
}), | |
]; | |
} | |
export default config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment