Skip to content

Commit 2539c49

Browse files
committed
fixes webpack2 lazy loading with syntax-dynamic-import
1 parent 77a9325 commit 2539c49

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ module.exports = {
157157
// @remove-on-eject-begin
158158
babelrc: false,
159159
presets: [require.resolve('babel-preset-react-app')],
160+
plugins: ['syntax-dynamic-import'],
160161
// @remove-on-eject-end
161162
// This is a feature of `babel-loader` for webpack (not Babel itself).
162163
// It enables caching results in ./node_modules/.cache/babel-loader/

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ module.exports = {
164164
options: {
165165
babelrc: false,
166166
presets: [require.resolve('babel-preset-react-app')],
167+
plugins: ['syntax-dynamic-import'],
167168
},
168169
// @remove-on-eject-end
169170
},

packages/react-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"babel-eslint": "7.1.1",
2929
"babel-jest": "18.0.0",
3030
"babel-loader": "6.3.2",
31+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
3132
"babel-preset-react-app": "^2.1.1",
3233
"babel-runtime": "^6.20.0",
3334
"case-sensitive-paths-webpack-plugin": "1.1.4",
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export default (store) => ({
22
path: '/about',
33
getComponent (nextState, cb) {
4-
require.ensure([], (require) => {
5-
const About = require('./containers/AboutContainer').default
6-
cb(null, About)
7-
}, 'about')
4+
import('./containers/AboutContainer').then((About) => {
5+
cb(null, About.default)
6+
}).catch((err) => {
7+
console.error('Failed to load module', err)
8+
})
89
}
910
})

0 commit comments

Comments
 (0)