我理解SERVER_API_URL是在webpack-common.js中定义的,默认为空。但是在制作中,我需要不同的api网址,我在"插件" webpack-prod.js中的数组,但看不到任何效果。我相信它必须与webpack-merge相关,现在它适用于DefinePlugin。我试着阅读webpack-merge的文档,但看起来需要很多阅读。
new webpack.DefinePlugin({
'process.env': {
// The root URL for API calls, ending with a '/' - for example: `"http://www.jhipster.tech:8081/myservice/"`.
// If this URL is left empty (""), then it will be relative to the current context.
// If you use an API server, in `prod` mode, you will need to enable CORS
// (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations)
SERVER_API_URL: '"http://172.26.0.150:9000/"'
}
})
该网址仍然是从webpack-common.js中获取的,并未被此设置覆盖。
答案 0 :(得分:0)
在以下堆栈溢出问题中找到了解决方案:How to set the REST api address in Angular according to build?
user2831852的建议效果很好:
SERVER_API_URL:options.env ==='开发'吗? developmentHost:productionHost