-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
考虑环境切换变量的实现 #271
Comments
roadhog.js里面配置 |
.roadhogrc.js define: {
'process.env': {},
'process.env.NODE_ENV': process.env.NODE_ENV,
'process.env.API_ENV': process.env.API_ENV,
}, 这样配置可行,覆盖 roadhog 默认配置,后面的都可以生效 |
@MinJieLiu 请教一下 如何配置一个测试环境啊? |
@weishijun14 测试环境一般是 |
@MinJieLiu API_ENV的值在哪设置呢 |
@huyawei 你楼上的楼上的楼上 |
@weishijun14 他那个只是进行了覆盖吧,值的入口呢,从哪里设置值 |
|
@MinJieLiu 跪谢 |
@sorrycc 建议尽快支持 dotenv
|
在.roadhogrc.js 添加define: { |
@Orecic 看我的评论 |
在.roadhogrc.js中添加define后:
报错: 请教下如何解决 |
.webpackrc 中添加, 报错 |
@MinJieLiu .webpackrc中添加报错
Error
Update
|
@xchunzhao @MinJieLiu 我参考你们的配置, .webpackrc.js文件如下: const path = require('path');
console.log('======', process.env);
export default {
entry: 'src/index.js',
define: {
'process.env': { a: 1 },
/*cannot set NODE_ENV for userDefined*/
'process.env.NODE_ENV': process.env.NODE_ENV,
'process.env.API_ENV': process.env.API_ENV,
},
extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
env: {
development: {
extraBabelPlugins: ['dva-hmr'],
},
},
alias: {
components: path.resolve(__dirname, 'src/components/'),
},
ignoreMomentLocale: true,
theme: './src/theme.js',
html: {
template: './src/index.ejs',
},
disableDynamicImport: true,
publicPath: '/',
hash: true,
};
"start:test": "cross-env API_ENV=test ESLINT=none roadhog dev", 在.webpackrc.js文件中是可以访问到 export default function request(url, options) {
console.log('process env in request....', process.env);// 这里打印出来是{}
if (process.env.API_ENV === 'test') {
url = API_PREFIX + url;
} 有空帮看一下呢, 谢谢~~ |
自己回答一下,之前理解错了。 其实在 |
mock中怎样使用define定义的变量 |
You can make this slightly nicer like this:
define: {
"process.env": {
NODE_ENV: process.env.NODE_ENV,
API_ENV: process.env.API_ENV
}
} |
Is there any way to load env vars from |
虽然代码里环境变量的值改变了 但是 配置proxy 还是走进了development。。。 |
The text was updated successfully, but these errors were encountered: