Skip to content

Commit

Permalink
Merge pull request #19 from shakacode/alex/node-legacy-babel-polyfill
Browse files Browse the repository at this point in the history
Load babel polyfill only for legacy node
  • Loading branch information
alex35mil committed Jan 16, 2016
2 parents 78d4886 + 51afb0b commit 6d84dda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/css-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 23 additions & 1 deletion src/bootstrap.loader.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 6d84dda

Please sign in to comment.