angular-cli:切换到 webpack 后环境文件替换被破坏(使用 `ng eject`) [英] angular-cli: environment file replacement is broken after switch to webpack (with `ng eject`)

查看:35
本文介绍了angular-cli:切换到 webpack 后环境文件替换被破坏(使用 `ng eject`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定为 angular-cli 使用扩展的 webpack 配置,所以我运行命令 ng eject.

I decided to use extended webpack configuration for angular-cli, so I ran command ng eject.

除了在angular-cli.json中指定的环境文件替换之外,看起来一切正常:

It looks like everything is working except environment file replacement, that is specified in angular-cli.json:

"environmentSource": "environments/environment.ts",
  "environments": {
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }

现在根本没有替换,它总是使用environments/environment.ts"文件.

Now there is not replacement at all and it always uses "environments/environment.ts" file.

有没有办法让它在不显着改变 webpack 配置的情况下工作?

Is there a way to make it work without significant changes for webpack config?

还为 angular-cli github 项目创建了一个问题.

Also created an issue for angular-cli github project.

推荐答案

好吧.. 我不得不编写自己的解决方案

Well.. I had to write my own solution

在 webpack 中,我更改了 AotPlugin 插件的配置:

And inside webpack I changed config for AotPlugin plugin:

hostReplacementPaths: {
  'environments/environment.ts': environmentFiles[NODE_ENV]
}

当然还有指定的environmentFiles:

const environmentFiles = {
  'development': 'environments/environment.dev.ts',
  'staging': 'environments/environment.stag.ts',
  'production': 'environments/environment.prod.ts'
};

这篇关于angular-cli:切换到 webpack 后环境文件替换被破坏(使用 `ng eject`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆