admin管理员组文章数量:1316980
Say I have alot of small apps, do I need to do a create-react-app for each one? Or can I have one create-react-app. The latter is my preference because I don't want a separate node_modules for each app. Because after the npm install it's hundred of megabytes.
If it's possible, what's the boiler I'd need to use to create multiple apps, is this is a webpack thing?
Say I have alot of small apps, do I need to do a create-react-app for each one? Or can I have one create-react-app. The latter is my preference because I don't want a separate node_modules for each app. Because after the npm install it's hundred of megabytes.
If it's possible, what's the boiler I'd need to use to create multiple apps, is this is a webpack thing?
Share Improve this question edited Feb 8, 2018 at 20:46 Shai UI asked Feb 8, 2018 at 20:36 Shai UIShai UI 52k77 gold badges217 silver badges316 bronze badges4 Answers
Reset to default 3You can use environment variables to do this.
Environment variables, that start with 'REACT_APP_' are available in the browser via process.env.REACT_APP_[NAME]
If you use an IDE like WebStorm, you can create different run configurations for every app and set Environment to REACT_APP_SETUP=app1
for example.
In the shell you can set it like this:
export REACT_APP_SETUP=app1
npm start
Then you just render different root ponents in your index.js
// in index.js
const setup = process.env.REACT_APP_SETUP;
if (setup == "app1") {
ReactDOM.render(<App1/>,document.getElementById('root'));
} else {
ReactDOM.render(<App2/>,document.getElementById('root'));
}
To create new app, Yes we need to create every time, But if we want all small apps inside one big app we may develop those small apps as 'Components' (which performs individually) and integrate inside one application.
When you create an app via create-react-app you create a new app from ground up. these apps use separate configuration files and are not meant to "talk" to each other. what you could do is to put each "app.js" file in one shared react-app and then rearrange these classes to share their contents (see import/export). But from my understanding it is not possible to have multiple react apps in one giant app
You can consider using react-app-rewired
But you won't get any support from create-react-app team, since its your own config. The other obvious solution is to eject.
Reference https://medium./@timarney/but-i-dont-wanna-eject-3e3da5826e39
本文标签: javascriptCreate React App for multiple appsStack Overflow
版权声明:本文标题:javascript - Create React App for multiple apps? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742017839a2414108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论