Skip to content

Commit

Permalink
Avoid including full Lodash build (#45)
Browse files Browse the repository at this point in the history
* Transform Lodash imports via Babel plugin (build: 513 kB -> 450 kB)
  • Loading branch information
nylen committed Nov 17, 2016
1 parent a8e2d13 commit 101743e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node

// webpack.config.prod.js checks this.
process.env.NODE_ENV = 'production';

// Load the create-react-app config.
const webpackConfigProd = require( 'react-scripts/config/webpack.config.prod' );

// Modify the config according to our needs.

const babelLoader = webpackConfigProd.module.loaders[ 0 ];
if ( babelLoader.loader !== 'babel' ) {
console.error( webpackConfigProd.module.loaders );
throw new Error( 'Couldn\'t find the babel loader config.' );
}

babelLoader.query.plugins = ( babelLoader.query.plugins || [] )
.filter( pluginName => pluginName !== 'lodash' )
.concat( 'lodash' );

console.log( 'Added lodash babel plugin to build' );

// Run the build.
require( 'react-scripts/scripts/build' );
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"devDependencies": {
"babel-eslint": "^7.1.0",
"babel-plugin-lodash": "^3.2.9",
"deep-freeze": "0.0.1",
"eslint": "^3.9.1",
"eslint-plugin-react": "^6.6.0",
Expand Down Expand Up @@ -33,10 +34,10 @@
},
"scripts": {
"start": "react-scripts start",
"build": "npm run lint && react-scripts build",
"build": "npm run lint && node bin/build.js",
"test": "npm run lint && react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint --ext js,jsx .eslintrc.js src/",
"lint": "eslint --ext js,jsx .eslintrc.js src/ bin/",
"deploy": "npm run build && surge -p ./build -d wpconsole.surge.sh"
}
}

0 comments on commit 101743e

Please sign in to comment.