diff --git a/bin/build.js b/bin/build.js new file mode 100755 index 0000000..e9bc8fb --- /dev/null +++ b/bin/build.js @@ -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' ); diff --git a/package.json b/package.json index d9b0080..c2b7357 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } }