Last active
October 7, 2016 03:41
-
-
Save deoxxa/7ac2021a5e0c34cfb4d9f803fc30001d to your computer and use it in GitHub Desktop.
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
const path = require('path'); | |
const webpack = require('webpack'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const byExtension = (obj) => Object.keys(obj).map((k) => Object.assign({ | |
test: new RegExp(`\.(${k})$`), | |
}, obj[k])); | |
if (process.env.NODE_ENV === 'production' && !process.env.API_URL) { | |
throw new Error('when NODE_ENV is "production", API_URL must be set'); | |
} | |
module.exports = { | |
devtool: 'source-map', | |
entry: { | |
browser: [ 'babel-polyfill', './src/entry-browser' ], | |
}, | |
output: { | |
path: path.join(__dirname, 'build'), | |
filename: '[name]-bundle.js', | |
publicPath: '/', | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'), | |
'process.env.API_URL': JSON.stringify(process.env.API_URL || ''), | |
}), | |
], | |
module: { | |
loaders: byExtension({ | |
'css': { | |
loaders: [ 'style', 'css?modules' ], | |
}, | |
'woff2?(\\?v=[0-9]\\.[0-9]\\.[0-9])?': { | |
loaders: [ 'url?limit=10000&mimetype=application/font-woff' ], | |
}, | |
'(ttf|eot|svg)(\\?v=[0-9]\\.[0-9]\\.[0-9])?': { | |
loaders: [ 'file' ], | |
}, | |
'js': { | |
loaders: [ 'babel' ], | |
include: path.join(__dirname, 'src'), | |
}, | |
'jpg': { | |
loaders: [ 'url?limit=10000&mimetype=image/jpeg', 'image-webpack' ], | |
}, | |
'png': { | |
loaders: [ 'url?limit=10000&mimetype=image/png', 'image-webpack' ], | |
}, | |
}), | |
}, | |
resolve: { | |
extensions: ['', '.js'], | |
alias: { | |
actions: path.join(__dirname, 'src', 'actions'), | |
components: path.join(__dirname, 'src', 'components'), | |
constants: path.join(__dirname, 'src', 'constants'), | |
containers: path.join(__dirname, 'src', 'containers'), | |
lib: path.join(__dirname, 'src', 'lib'), | |
reducers: path.join(__dirname, 'src', 'reducers'), | |
schema: path.join(__dirname, 'src', 'schema'), | |
}, | |
}, | |
}; | |
if (process.env.NODE_ENV === 'production') { | |
module.exports.output.filename = '[name]-bundle-[hash].js'; | |
module.exports.plugins.push(new ExtractTextPlugin('styles-[hash].css')); | |
module.exports.module.loaders.forEach((loader) => { | |
if (loader.loaders.indexOf('style') === 0) { | |
loader.loader = ExtractTextPlugin.extract(...loader.loaders); | |
delete loader.loaders; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment