diff --git a/examples/simple/package.json b/examples/simple/package.json index 5cabf36f..f3d0095c 100644 --- a/examples/simple/package.json +++ b/examples/simple/package.json @@ -4,7 +4,8 @@ "description": "Simple example", "main": "server.js", "scripts": { - "start": "node server.js" + "start": "NODE_ENV=development node server.js", + "build": "NODE_ENV=production ./node_modules/.bin/webpack" }, "repository": { "type": "git", diff --git a/examples/simple/webpack.config.js b/examples/simple/webpack.config.js index c4f927e3..b4382bea 100644 --- a/examples/simple/webpack.config.js +++ b/examples/simple/webpack.config.js @@ -1,22 +1,60 @@ var path = require('path'); var webpack = require('webpack'); +var entry = []; +if(process.env.NODE_ENV === 'development') { + entry.push( + 'webpack-dev-server/client?http://localhost:3000', + 'webpack/hot/only-dev-server' + ); +} + +var plugins = [ + new webpack.HotModuleReplacementPlugin(), + new webpack.NoErrorsPlugin() +]; +if(process.env.NODE_ENV === 'production') { + plugins.push( + new webpack.optimize.UglifyJsPlugin({ + compress: { + warnings: false + } + }) + ); +} + +var loaders = []; +if(process.env.NODE_ENV === 'development') { + loaders.push({ + test: /\.js$/, + loaders: ['react-hot', 'babel'], + exclude: /node_modules/, + include: __dirname + }); +} else { + loaders.push({ + test: /\.js$/, + loaders: ['babel'], + exclude: /node_modules/, + include: __dirname + }); +} + +loaders.push({ + test: /\.js$/, + loaders: ['babel'], + include: path.join(__dirname, '..', '..', 'src') +}); + module.exports = { devtool: 'eval', - entry: [ - 'webpack-dev-server/client?http://localhost:3000', - 'webpack/hot/only-dev-server', - './index' - ], + entry: entry.concat('./index'), output: { path: path.join(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/static/' }, - plugins: [ - new webpack.HotModuleReplacementPlugin(), - new webpack.NoErrorsPlugin() - ], + plugins: plugins, resolve: { alias: { 'react-custom-scrollbars': path.join(__dirname, '..', '..', 'src') @@ -24,15 +62,6 @@ module.exports = { extensions: ['', '.js'] }, module: { - loaders: [{ - test: /\.js$/, - loaders: ['react-hot', 'babel'], - exclude: /node_modules/, - include: __dirname - }, { - test: /\.js$/, - loaders: ['babel'], - include: path.join(__dirname, '..', '..', 'src') - }] + loaders: loaders } };