admin管理员组文章数量:1316980
I'm using react lazy for route based code splitting as described here: .html#route-based-code-splitting
My routes file looks like this:
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import React, { Suspense, lazy } from 'react';
const APage = lazy(() => import(/* webpackChunkName: "APage" */ '../pages/APage'));
const BPage = lazy(() => import(/* webpackChunkName: "BPage" */ '../pages/BPage'));
const App = () => (
<Router>
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route exact path="/products/a" ponent={APage}/>
<Route exact path="/products/b" ponent={BPage}/>
</Switch>
</Suspense>
</Router>
);
When I pile the app it correctly generates 4 JS chunks:
app.js
APage.js
BPage.js
APage~BPage.js
however when I navigate to this path: /products/a
, I get these load errors because my ponent files are located in the root, not in a 'products' folder:
:3000/products/APage~BPage.js net::ERR_ABORTED 404 (Not Found)
:3000/products/APage.js net::ERR_ABORTED 404 (Not Found)
How can I configure webpack/react to load ponents from the root of my site and/or from an external CDN?
I'm using react lazy for route based code splitting as described here: https://reactjs/docs/code-splitting.html#route-based-code-splitting
My routes file looks like this:
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import React, { Suspense, lazy } from 'react';
const APage = lazy(() => import(/* webpackChunkName: "APage" */ '../pages/APage'));
const BPage = lazy(() => import(/* webpackChunkName: "BPage" */ '../pages/BPage'));
const App = () => (
<Router>
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route exact path="/products/a" ponent={APage}/>
<Route exact path="/products/b" ponent={BPage}/>
</Switch>
</Suspense>
</Router>
);
When I pile the app it correctly generates 4 JS chunks:
app.js
APage.js
BPage.js
APage~BPage.js
however when I navigate to this path: /products/a
, I get these load errors because my ponent files are located in the root, not in a 'products' folder:
http://localhost.:3000/products/APage~BPage.js net::ERR_ABORTED 404 (Not Found)
http://localhost.:3000/products/APage.js net::ERR_ABORTED 404 (Not Found)
How can I configure webpack/react to load ponents from the root of my site and/or from an external CDN?
Share Improve this question edited Apr 3, 2019 at 21:35 Cbas asked Apr 3, 2019 at 21:29 CbasCbas 6,21311 gold badges62 silver badges89 bronze badges1 Answer
Reset to default 6in webpack 's module add output values like this :
output: {
publicPath: '/',
path: path.join(__dirname, 'root'),
}
本文标签: javascriptset chunk path a with webpack and react lazy code splittingStack Overflow
版权声明:本文标题:javascript - set chunk path a with webpack and react lazy code splitting - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742010198a2412746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论