[英]Separate Develop and Production files in npm or webpack
I have seen in react native project, we use index.android.js
and index.ios.js
to separate index.js
file for android and ios.我在 react native 项目中看到,我们使用
index.android.js
和index.ios.js
来分隔 android 和 ios 的index.js
文件。
Now is it possible for develop
and production
environment to separate their files ??现在
develop
环境和production
环境可以分开文件吗?? I mean does webpack
or a plugin or maybe node
have any ability to separate them like index.develop.js
and index.js
(for production) and require it like require('index')
?我的意思是
webpack
或插件或node
是否有能力将它们分开,如index.develop.js
和index.js
(用于生产)并像require('index')
一样require('index')
它?
Yes sure, using process.env.NODE_ENV
you can dynamically require()
:是的,使用
process.env.NODE_ENV
你可以动态地require()
:
const module = process.env.NODE_ENV === "production"
? require("./production")
: require("./development");
Then if production mode is on, the comparison will be inlined, and the require("./development")
will be optimized away.然后,如果生产模式打开,比较将被内联,并且
require("./development")
将被优化掉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.