Skip to content

Commit 2288ddf

Browse files
authored
Support & test import() for non-bundled code (#1615)
* Test basic import syntax * Compile import() in test, only support syntax otherwise
1 parent 3289c32 commit 2288ddf

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
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",
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import Promises from './Promises';
43

54
describe('promises', () => {
65
it('renders without crashing', () => {
76
const div = document.createElement('div');
8-
return new Promise(resolve => {
9-
ReactDOM.render(<Promises onReady={resolve} />, div);
7+
return import('./Promises').then(({ default: Promises }) => {
8+
return new Promise(resolve => {
9+
ReactDOM.render(<Promises onReady={resolve} />, div);
10+
});
1011
});
1112
});
1213
});

0 commit comments

Comments
 (0)