After reading this post , I tried to use react-code-splitting to splite my JavaScript bundle.
Webpack Version: 3.10.10
import Async from "react-code-splitting";
import React from "react";
// import Home from "pages/home/Home";
// ...
const Home = () => <Async load={import("pages/home/Home")} />
export default class PageRouter extends React.Component {
render() {
return(
<Router history={browserHistory}>
<Route exact path="/" component={Home} />
</Router>
);
}
}
It seems like just a syntax problem?
export default class PageRouter extends React.Component {
render() {
^
return (...);
}
}
webpack: Failed to compile.
I can't really tell what the root issue is but, I suspect that perhaps you are missing some babel plugins. Check out Paragons . It uses React Loadable. You can cross check the webpack config and examine the usage:
Start from:
export const CodeSplitPageLoadable = createLoadable('./demo/components/CodeSplitPage')
in routes.js .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.