Jhipster:如何为产品Webpack配置文件覆盖SERVER_API_URL

问题描述 投票:4回答:1

我了解SERVER_API_URL在webpack-common.js中定义,默认情况下为空。但是在生产中,我将需要用于API的其他URL,我在webpack-prod.js的“ plugins”数组中添加了以下内容,但没有看到任何效果。我认为它必须与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/"'
        }
    })

URL仍从webpack-common.js中获取,并且未被此设置覆盖。

webpack jhipster webpack-2
1个回答
0
投票

在此stackoverflow问题中找到了一个解决方案:How to set the REST api address in Angular according to build?

user2831852的建议效果很好:

SERVER_API_URL:options.env ==='开发'吗? developmentHost:productionHost

© www.soinside.com 2019 - 2024. All rights reserved.