From 51afb0bc52c1b21f06d4d009ab6daf435fcb5071 Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Fri, 15 Jan 2016 14:35:07 +0300 Subject: [PATCH] Load babel polyfill only for legacy node --- examples/basic/package.json | 2 +- examples/css-modules/package.json | 2 +- src/bootstrap.loader.js | 24 +++++++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/examples/basic/package.json b/examples/basic/package.json index c355a53e..d8f1e2a2 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -43,7 +43,7 @@ "babel-loader": "^6.1.0", "babel-preset-es2015": "^6.1.18", "body-parser": "^1.14.1", - "bootstrap-loader": "^1.0.0-rc", + "bootstrap-loader": "file:../../.", "css-loader": "^0.22.0", "eslint": "^1.9.0", "eslint-config-airbnb": "^1.0.0", diff --git a/examples/css-modules/package.json b/examples/css-modules/package.json index 487ac0ca..29ccda07 100644 --- a/examples/css-modules/package.json +++ b/examples/css-modules/package.json @@ -51,7 +51,7 @@ "babel-preset-es2015": "^6.3.13", "babel-preset-react": "^6.3.13", "body-parser": "^1.14.1", - "bootstrap-loader": "^1.0.0-rc", + "bootstrap-loader": "file:../../.", "css-loader": "^0.23.0", "eslint": "^1.9.0", "eslint-config-airbnb": "^1.0.0", diff --git a/src/bootstrap.loader.js b/src/bootstrap.loader.js index 1db7f7f3..32d0010a 100644 --- a/src/bootstrap.loader.js +++ b/src/bootstrap.loader.js @@ -1,6 +1,28 @@ /* eslint func-names: 0 */ -import 'babel-polyfill'; +import semver from 'semver'; + +// For Node <= v0.12.x Babel polyfill is required +if (semver.lt(process.version, '4.0.0')) { + const babelLatest = 'babel-polyfill'; + const babelPrev = 'babel/polyfill'; + + const isBabelLatest = require.resolve(babelLatest); + const isBabelPrev = require.resolve(babelPrev); + + if (!isBabelLatest && !isBabelPrev) { + throw new Error(` + For Node <= v0.12.x Babel polyfill is required. + Make sure it's installed in your 'node_modules/' directory. + `); + } + + if (isBabelLatest) { + require(babelLatest); + } else { + require(babelPrev); + } +} import path from 'path'; import loaderUtils from 'loader-utils';