Skip to content

Commit c2ab8fb

Browse files
committed
Compile import() in test, only support syntax otherwise
1 parent a373aec commit c2ab8fb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/babel-preset-react-app/index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ const plugins = [
3030
regenerator: true,
3131
// Resolve the Babel runtime relative to the config.
3232
moduleName: path.dirname(require.resolve('babel-runtime/package'))
33-
}],
34-
// Enables parsing of import()
35-
require.resolve('babel-plugin-syntax-dynamic-import')
33+
}]
3634
];
3735

3836
// This is similar to how `env` works in Babel:
@@ -77,7 +75,10 @@ if (env === 'test') {
7775
// JSX, Flow
7876
require.resolve('babel-preset-react')
7977
],
80-
plugins: plugins
78+
plugins: plugins.concat([
79+
// Compiles import() to a deferred require()
80+
require.resolve('babel-plugin-dynamic-import-node')
81+
])
8182
};
8283
} else {
8384
module.exports = {
@@ -97,6 +98,8 @@ if (env === 'test') {
9798
// Async functions are converted to generators by babel-preset-latest
9899
async: false
99100
}],
101+
// Adds syntax support for import()
102+
require.resolve('babel-plugin-syntax-dynamic-import'),
100103
])
101104
};
102105

packages/babel-preset-react-app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"index.js"
1212
],
1313
"dependencies": {
14+
"babel-plugin-dynamic-import-node": "1.0.0",
1415
"babel-plugin-syntax-dynamic-import": "6.18.0",
1516
"babel-plugin-transform-class-properties": "6.22.0",
1617
"babel-plugin-transform-object-rest-spread": "6.22.0",

0 commit comments

Comments
 (0)