commit ffdf981522757455252a49d6e9e9e6d35beb5620
parent b2438cdc3644a37c8dde974b408e6f61d144c5bc
Author: Konstantin Tarkus <hello@tarkus.me>
Date: Wed, 12 Aug 2015 02:19:27 +0300
Update Webpack config; remove minimist dependency
Diffstat:
5 files changed, 23 insertions(+), 38 deletions(-)
diff --git a/README.md b/README.md
@@ -70,19 +70,17 @@ $ npm start # Compile and launch
### How to Build
```shell
-$ npm run build # or, `npm run build --release`
+$ npm run build # or, `npm run build -- release`
```
By default, it builds in a *debug* mode. If you need to build in a release
-mode, just add `--release` flag. This will optimize the output bundle for
-production deployment; you will also see some warnings from
-[uglify](https://github.com/mishoo/UglifyJS) where it removes unused code from
-your release.
+mode, just add `-- release` flag. This will optimize the output bundle for
+production deployment.
### How to Run
```shell
-$ npm start # or, `npm start --release`
+$ npm start # or, `npm start -- release`
```
This will start a lightweight development server with "live reload" and
@@ -91,7 +89,7 @@ synchronized browsing across multiple devices and browsers.
### How to Deploy
```shell
-$ npm run deploy # or, `npm run deploy --production`
+$ npm run deploy # or, `npm run deploy -- production`
```
For more information see `tools/deploy.js`.
diff --git a/package.json b/package.json
@@ -37,7 +37,6 @@
"git-push": "^0.1.1",
"glob": "^5.0.14",
"jest-cli": "^0.4.18",
- "minimist": "^1.1.3",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"postcss": "^4.1.16",
diff --git a/tools/bundle.js b/tools/bundle.js
@@ -8,11 +8,8 @@
*/
import webpack from 'webpack';
-import minimist from 'minimist';
import config from './config';
-const argv = minimist(process.argv.slice(2));
-
/**
* Bundles JavaScript, CSS and images into one or more packages
* ready to be used in a browser.
@@ -20,7 +17,6 @@ const argv = minimist(process.argv.slice(2));
export default async () => new Promise((resolve, reject) => {
console.log('bundle');
const bundler = webpack(config);
- const verbose = !!argv.verbose;
let bundlerRunCount = 0;
function bundle(err, stats) {
@@ -28,16 +24,7 @@ export default async () => new Promise((resolve, reject) => {
return reject(err);
}
- console.log(stats.toString({
- colors: true,
- hash: verbose,
- version: verbose,
- timings: verbose,
- chunks: verbose,
- chunkModules: verbose,
- cached: verbose,
- cachedAssets: verbose
- }));
+ console.log(stats.toString(config[0].stats));
if (++bundlerRunCount === (global.watch ? config.length : 1)) {
return resolve();
diff --git a/tools/config.js b/tools/config.js
@@ -10,12 +10,10 @@
import path from 'path';
import webpack, { DefinePlugin, BannerPlugin } from 'webpack';
import merge from 'lodash/object/merge';
-import minimist from 'minimist';
-const argv = minimist(process.argv.slice(2));
-const DEBUG = !argv.release;
+const DEBUG = !process.argv.includes('release');
const WATCH = global.WATCH === undefined ? false : global.WATCH;
-const VERBOSE = global.VERBOSE === undefined ? false : global.VERBOSE;
+const VERBOSE = process.argv.includes('verbose');
const STYLE_LOADER = 'style-loader/useable';
const CSS_LOADER = DEBUG ? 'css-loader' : 'css-loader?minimize';
const AUTOPREFIXER_BROWSERS = [
@@ -86,8 +84,8 @@ const config = {
}, {
test: /\.jsx?$/,
include: [
- path.resolve(__dirname, 'node_modules/react-routing/src'),
- path.resolve(__dirname, 'src')
+ path.resolve(__dirname, '../node_modules/react-routing/src'),
+ path.resolve(__dirname, '../src')
],
loaders: [...(WATCH ? ['react-hot'] : []), 'babel-loader']
}]
@@ -111,21 +109,23 @@ const appConfig = merge({}, config, {
'./src/app.js'
],
output: {
- path: path.join(__dirname, 'build', 'public'),
+ path: path.join(__dirname, '../build/public'),
filename: 'app.js'
},
devtool: DEBUG ? 'source-map' : false,
- plugins: config.plugins.concat([
- new DefinePlugin(merge(GLOBALS, {'__SERVER__': false}))
- ].concat(DEBUG ? [] : [
+ plugins: [
+ ...config.plugins,
+ new DefinePlugin(merge(GLOBALS, {'__SERVER__': false})),
+ ...(DEBUG ? [] : [
new webpack.optimize.DedupePlugin(),
- new webpack.optimize.UglifyJsPlugin(),
+ new webpack.optimize.UglifyJsPlugin({compress: {warnings: VERBOSE}}),
new webpack.optimize.AggressiveMergingPlugin()
- ]).concat(WATCH ? [
+ ]),
+ ...(WATCH ? [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
] : [])
- ),
+ ],
module: {
loaders: [...config.module.loaders, {
test: /\.css$/,
@@ -164,11 +164,12 @@ const serverConfig = merge({}, config, {
__dirname: false
},
devtool: DEBUG ? 'source-map' : 'cheap-module-source-map',
- plugins: config.plugins.concat(
+ plugins: [
+ ...config.plugins,
new DefinePlugin(merge(GLOBALS, {'__SERVER__': true})),
new BannerPlugin('require("source-map-support").install();',
{ raw: true, entryOnly: false })
- ),
+ ],
module: {
loaders: [...config.module.loaders, {
test: /\.css$/,
diff --git a/tools/start.js b/tools/start.js
@@ -13,7 +13,7 @@ import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
global.WATCH = true;
-const config = require('../webpack.config')[0]; // Client-side bundle config
+const config = require('./config')[0]; // Client-side bundle configuration
const bundler = webpack(config);
/**