我正在尝试使用 create-react-app 创建一个简单的网络应用程序。我已将页面和组件移动到标记为 pages
的 src 下的单独目录中和 components
.我想将 index.js 的入口点从 src/index.js 更改/添加到 src/pages/index.js。另一种选择是将 index.js 保留在 src/并从页面和组件目录导入。有人可以帮我找到如何更改入口点路径吗?
我似乎找不到默认 html-webpack-plugin 配置文件的位置。
这是我希望的结构:
(in src)
...
pages/
- App.js
- Home.js
components/
- Filter.js
serviceWorker.js
最佳答案
我使用 react-rewired 来实现这样的目标:
https://github.com/timarney/react-app-rewired/issues/189
在我的 config-overrides.js
console.log("@@@@@@@@@@@@@@@@@@@@@@@");
console.log("@ using react-rewired @");
console.log("@@@@@@@@@@@@@@@@@@@@@@@");
module.exports = {
// The Webpack config to use when compiling your react app for development or production.
webpack: function(config, env) {
// ...add your webpack config
console.log("@@@@@@@@@@@");
console.log("@ webpack @");
console.log("@@@@@@@@@@@");
console.log({config, env});
if (env === 'development') {
config.entry = config.entry.replace(new RegExp("index.ts$"), 'runApp.tsx');
console.log("entry point changed:", config.entry);
}
return config;
},
}
我需要在不同的文件上运行,但仅在运行开发服务器时上面的链接有完整的解决方案
关于javascript - 更改/添加 index.js 的 create-react-app 入口点或位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55494682/