reactjs - 动态导入不适用于 Webpack 4 + React + @loadable/component
问题描述
我有一个将 React 与 Webpack 4、Babel 和 TypeScript 一起使用的项目。我正在尝试为此进行代码拆分和安装@loadable/component
。不幸的是,当我调用loadable(() => import(...))
以将我的一个页面放在不同的块中时,webpack 或 babel 似乎没有意识到这一点,没有任何反应,我只保留一个 JS 文件。搜索文档,SO 的其他问题,但似乎没有任何效果 =\
这是我的.tsx
文件:
import loadable from "@loadable/component";
const TextDisplayPage = loadable(() => import("./pages/textDisplayPage"));
const AppRoutes = () => (
<Switch>
<Route exact path="/" component={HomePage} />
<Route
exact
path="/introduction"
render={() => (
<TextDisplayPage
textsToDisplay={DisplayTexts.INTRODUCTION}
continueButtonLinkURL="/character"
/>
)}
/>
</Switch>
);
我的.babelrc
文件:
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["@loadable/babel-plugin", "@babel/plugin-syntax-dynamic-import"]
}
我的webpack.config.js
文件的一部分(不知道这是否足够的信息,但如果不是让我知道的话):
/*...*/
module: {
rules: [
{
test: /\.tsx?$/,
exclude: [/node_modules/],
use: ["babel-loader", "ts-loader"],
}
]
/*...*/
任何帮助表示赞赏。提前致谢!
解决方案
推荐阅读
- python - Python,就地加载共享对象
- python-3.x - 当我让机器人以 discord py 发送项目列表时,如何删除项目列表?
- c++ - PyBind11:在 Python 中访问唯一的指针属性
- python - 如何从目标中删除字符溢出
- c++ - 从 getline 中取出垃圾
- python - 为什么枚举应该接受一个集合作为输入?
- c# - 如何检索选择一种类型的条目,该条目具有其他类型的条目?
- python-3.x - NotImplementedError:目前不支持具有未命名曲线的 ECDSA 证书
- http - 为什么我的 http 请求正文没有传输到服务器?
- python - 尝试使用 for 循环和附加列表将图像 URL 添加到列表以进行网络抓取