【问题标题】:webpack AngularCompilerPlugin hostReplacementPaths option does not workwebpack AngularCompilerPlugin hostReplacementPaths 选项不起作用
【发布时间】:2019-01-11 13:09:46
【问题描述】:

在我更新到 Angular6 并将 @ngtools/webpack 从“6.0.0-beta.8”更新到“6.1.2”后,我发现 hostReplacementPaths 选项不再起作用了。

通常它会替换正确的 env 文件:

new AngularCompilerPlugin({
  ...
  hostReplacementPaths: {
    'environments/environment.ts': environmentFiles[NODE_ENV]
  },
  ...
})

但现在没有了。

我对@ngtools/webpack进行了深度调试,发现normalize函数在这里 https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/virtual_file_system_decorator.ts#L188 不工作

这个 https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/core/src/virtual-fs/path.ts#L199

仍然找不到问题所在。 也许有人已经解决了这个问题?

在 angular-cli repo 中创建了一个问题 - https://github.com/angular/angular-cli/issues/11801

【问题讨论】:

    标签: angular webpack ngtools


    【解决方案1】:

    看起来这个 PR 很快就会修复 - https://github.com/angular/angular-cli/pull/11809

    正如 James 所说,此提交在 6.1.0-rc.2 中引入了一个错误:https://github.com/angular/angular-cli/commit/86a62adbe8faeb4628296d5d6915c54e6dbfd85b

    路径未正确解析。

    之前:

    const normalizedFrom = normalize(from);
    const normalizedWith = normalize(this._options.hostReplacementPaths[from]);
    

    建议修复:

    const normalizedFrom = resolve(normalize(this._basePath), normalize(from));
    
    const normalizedWith = resolve(
      normalize(this._basePath),
      normalize(this._options.hostReplacementPaths[from]),
    );
    

    【讨论】:

      【解决方案2】:

      正如您在问题中提到的,这是 6.1.0-rc.2 版本的一个已知错误,在推出补丁之前,您应该降级回 6.1.0-rc.1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-30
        • 1970-01-01
        • 2017-07-16
        • 1970-01-01
        • 2021-01-27
        • 2017-08-07
        相关资源
        最近更新 更多