-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid including full Lodash build (#45)
* Transform Lodash imports via Babel plugin (build: 513 kB -> 450 kB)
- Loading branch information
Showing
2 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters