更改/添加create-react-app入口点或index.js的位置 [英] Change/add create-react-app entry point or location of index.js

查看:896
本文介绍了更改/添加create-react-app入口点或index.js的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用create-react-app创建一个简单的Web应用程序。我已将页面和组件移到src下分别标记为 pages components 的单独目录中。我想将index.js的入口点从src / index.js更改/添加到src / pages / index.js。另一个选择是将index.js保留在src /中,并从页面和组件目录导入。有人可以帮助我找到如何更改入口点路径吗?

I am trying to use create-react-app to create a simple web-app. I have moved the pages and components into separate directories under src labeled pages and components. I would like to change/add the entry point for index.js from src/index.js to src/pages/index.js. Another option would be to keep index.js in src/ and import from pages and component directories. Can someone help me to find how i can change the entry point path?

我似乎找不到默认的html-webpack-plugin配置文件的位置。

I can't seem to find the location of the default html-webpack-plugin config file.

这就是我想要的结构:

(in src)
...
pages/
   - App.js
   - Home.js

components/
   - Filter.js

serviceWorker.js


推荐答案

这是使用 create-react-app@3.4.1 所需的确切更改。运行 npm run弹出之后,两个新文件夹即 config 脚本将添加到项目主目录中。

更新条目: appIndexJs:resolveModule(resolveApp,'src / index') appIndexJs:resolveModule(resolveApp,'src / pages / index')。之后,您可以照常构建/运行项目。

This is the exact change required with create-react-app@3.4.1. After running npm run eject, two new folders viz config and scripts will be added in the project home directory.
Update the entry : appIndexJs: resolveModule(resolveApp, 'src/index') to appIndexJs: resolveModule(resolveApp, 'src/pages/index'). After this, you can build/run the project as usual.

这篇关于更改/添加create-react-app入口点或index.js的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆