Skip to content

Commit 6d84dda

Browse files
committed
Merge pull request #19 from shakacode/alex/node-legacy-babel-polyfill
Load babel polyfill only for legacy node
2 parents 78d4886 + 51afb0b commit 6d84dda

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

examples/basic/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"babel-loader": "^6.1.0",
4444
"babel-preset-es2015": "^6.1.18",
4545
"body-parser": "^1.14.1",
46-
"bootstrap-loader": "^1.0.0-rc",
46+
"bootstrap-loader": "file:../../.",
4747
"css-loader": "^0.22.0",
4848
"eslint": "^1.9.0",
4949
"eslint-config-airbnb": "^1.0.0",

examples/css-modules/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"babel-preset-es2015": "^6.3.13",
5252
"babel-preset-react": "^6.3.13",
5353
"body-parser": "^1.14.1",
54-
"bootstrap-loader": "^1.0.0-rc",
54+
"bootstrap-loader": "file:../../.",
5555
"css-loader": "^0.23.0",
5656
"eslint": "^1.9.0",
5757
"eslint-config-airbnb": "^1.0.0",

src/bootstrap.loader.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
/* eslint func-names: 0 */
22

3-
import 'babel-polyfill';
3+
import semver from 'semver';
4+
5+
// For Node <= v0.12.x Babel polyfill is required
6+
if (semver.lt(process.version, '4.0.0')) {
7+
const babelLatest = 'babel-polyfill';
8+
const babelPrev = 'babel/polyfill';
9+
10+
const isBabelLatest = require.resolve(babelLatest);
11+
const isBabelPrev = require.resolve(babelPrev);
12+
13+
if (!isBabelLatest && !isBabelPrev) {
14+
throw new Error(`
15+
For Node <= v0.12.x Babel polyfill is required.
16+
Make sure it's installed in your 'node_modules/' directory.
17+
`);
18+
}
19+
20+
if (isBabelLatest) {
21+
require(babelLatest);
22+
} else {
23+
require(babelPrev);
24+
}
25+
}
426

527
import path from 'path';
628
import loaderUtils from 'loader-utils';

0 commit comments

Comments
 (0)