From d6c466074d781bb89405f7827f22acbf99b88d51 Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Sat, 19 Nov 2016 18:37:23 -0800 Subject: [PATCH] Stop Babel requiring entire package.json just to get core version number. Reduces build size by ~3 KB --- gulpfile.js | 5 +++++ src/babel-package-shim.js | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 src/babel-package-shim.js diff --git a/gulpfile.js b/gulpfile.js index ca463f4..4f096cd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -38,6 +38,7 @@ function webpackBuild(filename, libraryName, version) { plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"', + BABEL_VERSION: JSON.stringify(require('babel-core/package.json').version), VERSION: JSON.stringify(version), }), // Use browser version of visionmedia-debug @@ -45,6 +46,10 @@ function webpackBuild(filename, libraryName, version) { /debug\/node/, 'debug/browser' ), + new webpack.NormalModuleReplacementPlugin( + /..\/..\/package/, + '../../../../src/babel-package-shim' + ), new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.DedupePlugin() ] diff --git a/src/babel-package-shim.js b/src/babel-package-shim.js new file mode 100644 index 0000000..7e91b7e --- /dev/null +++ b/src/babel-package-shim.js @@ -0,0 +1,5 @@ +/** + * A shim that replaces Babel's require('package.json') statement. + * Babel requires the entire package.json file just to get the version number. + */ +export const version = BABEL_VERSION;