webpack - Jhipster:如何覆盖 prod webpack 配置文件的 SERVER_API_URL

标签 webpack jhipster webpack-2

我知道 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 中获取,并且尚未被此设置覆盖。

最佳答案

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

user2831852的建议效果很好:

SERVER_API_URL:options.env ===“开发”?开发主机:生产主机

关于webpack - Jhipster:如何覆盖 prod webpack 配置文件的 SERVER_API_URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50360438/

相关文章:

javascript - 动态加载外部 webpack 捆绑的 ngModule 作为路由处理程序

java - jHipster:如何在 jdl 导入期间仅生成实体

microservices - Jhipster import-jdl不生成实体

reactjs - 使用 React-Bootstrap 的 Webpack,大量 'Module Not Found' 错误

fonts - 无法使用 webpack 和 vuejs 加载字体

jhipster - JHipster 是否打算用作任何 Java Web 应用程序的 Backbone ?

javascript - Webpack DllPlugin with gulp : Cannot find module '... vendor-manifest.json'

javascript - Webpack 2.3.3 - 类型错误 : $export is not a function

asp.net - 分布式软件架构中的捆绑优化

json - Angular 6 - JSON 中位置 0 的意外标记