Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Add a dev-only config for webpack and optimize main build for production
Browse files Browse the repository at this point in the history
Summary:
This diff optimizes our `webpack.config.js` for production by pointing to the React production build
(to disable `PropType` validation, which is quite slow), enabling Uglify, and disabling source maps.
In addition, it defines a separate `webpack.config.dev.js` which reverts all of these changes and an
`npm run watch` command that points to the dev settings. This is a similar setup to what we have for
our mobile JS (see [here](https://github.com/Khan/mobile-client-webview-resources/tree/master/javascript)).

On Asana @ https://app.asana.com/0/114493820703878/119470924649091.

Test Plan:
- Run `webpack`.
    - Verify that the produced build is relatively small (< 400 KB).
    - Open up the keypad.
    - Enable profiling in Devtools.
    - Swipe around a bit.
        - Verify that there is no `PropType` validation going on.
- Run `npm run watch`.
    - Verify that the produced build is much larger (~2 MB).
    - Verify that `PropType` validation is back.

Reviewers: kevinb

Reviewed By: kevinb

Differential Revision: https://phabricator.khanacademy.org/D27229
  • Loading branch information
Charles Marsh committed May 11, 2016
1 parent d07d3f3 commit 042de9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "mocha test/test_*.js --compilers js:babel-register",
"watch_test": "mocha test/test_spec.js --watch --compilers js:babel-register",
"start": "webpack -w"
"watch": "webpack --config webpack.config.dev.js --watch"
},
"author": "",
"license": "MIT",
Expand Down
17 changes: 17 additions & 0 deletions webpack.config.dev.js
@@ -0,0 +1,17 @@
const webpack = require('webpack');

const config = require('./webpack.config');

// Same plugins as the production config, except:
// (1) No Uglify minification.
// (2) No production Node environment (which is used in production to disable
// React's PropTypes validation).
config.plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'deps',
}),
];

config.devtool = '#eval-source-map';

module.exports = config;
14 changes: 8 additions & 6 deletions webpack.config.js
Expand Up @@ -2,7 +2,6 @@ const path = require('path');
const webpack = require('webpack');

module.exports = {
devtool: '#eval-source-map',
entry: {
app: './src/index',
deps: [
Expand All @@ -23,11 +22,14 @@ module.exports = {
new webpack.optimize.CommonsChunkPlugin({
name: 'deps',
}),
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false
// }
// }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
],
resolve: {
extensions: ['', '.js', '.jsx'],
Expand Down

0 comments on commit 042de9a

Please sign in to comment.