Reputation: 515
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.
Now is it possible for develop
and production
environment to separate their files ??
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')
?
Upvotes: 1
Views: 52
Reputation: 138287
Yes sure, using process.env.NODE_ENV
you can dynamically 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.
Upvotes: 1