我有一个命中 API的React on Rails应用程序。我想将 API 端点配置为localhost
用于开发,并将我部署的应用程序的 URL 配置为用于生产。
客户端/package.json
"scripts": {
"build:production": "NODE_ENV=production webpack --config webpack.config.js",
},
客户端/webpack.config.js
const devBuild = process.env.NODE_ENV !== 'production';
const config = {
entry: [
'es5-shim/es5-shim',
'es5-shim/es5-sham',
'babel-polyfill',
'./app/bundles/Main/startup/registration',
],
output: {
filename: 'webpack-bundle.js',
path: __dirname + '/../app/assets/webpack',
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new webpack.EnvironmentPlugin({ NODE_ENV: 'development' }),
]
}
我看到它process.env.NODE_ENV
在 config/webpack.config.js 中可用(这里用于将源映射开发工具添加到模块导出中),但我想要一种方法来查看我的 React 代码中某个地方的环境是什么client/
。如果有的话,我有什么选择?