Merge branch 'productionBuild' into 'master'

Optimize webpack for production builds

See merge request !23
This commit is contained in:
Lucas 2016-11-30 09:51:06 +00:00
commit 980a7bf266
3 changed files with 20 additions and 4 deletions

View File

@ -78,3 +78,9 @@ make test
```
make clean
```
## Production build
```
yarn build
```

View File

@ -1,7 +1,8 @@
{
"name": "canape",
"scripts": {
"start": "./node_modules/webpack/bin/webpack.js -d --progress --colors --watch"
"start": "NODE_ENV=development ./node_modules/webpack/bin/webpack.js -d --progress --colors --watch",
"build": "NODE_ENV=production ./node_modules/webpack/bin/webpack.js -p --progress --colors"
},
"dependencies": {
"babel-polyfill": "^6.16.0",

View File

@ -4,13 +4,12 @@ var path = require("path");
var BUILD_DIR = path.resolve(__dirname, 'build/public/');
var SRC_DIR = path.resolve(__dirname, 'src/public/js');
module.exports = {
const config = {
entry: path.join(SRC_DIR, 'app.js'),
output: {
path: BUILD_DIR,
filename: 'js/app.js',
},
devtool: 'source-map',
module: {
loaders: [
{
@ -39,10 +38,20 @@ module.exports = {
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
],
resolve: {
extensions: ['', '.js', '.jsx']
},
};
if (process.env.NODE_ENV === 'production') {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin()
)
} else {
config.devtool = "#cheap-module-source-map"
}
module.exports = config;