【问题标题】:How to use module name aliasing in angular cli?如何在 Angular cli 中使用模块名称别名?
【发布时间】:2016-09-30 11:30:35
【问题描述】:

使用独立的 webpack,您可以使用别名来解析模块。 在你的 webpack.config 文件 config.resolve 块中类似这样的东西:

config.resolve = {
    extensions: ['', '.ts', '.js', '.json', '.css', '.scss', '.html'],
    alias: {
      'app': 'src/app',
      'common': 'src/common',
       'a_module_name': 'file_path_to_module_name'
    }
  };

如何在 Angular cli 中使用 webpack 之类的别名解析?

【问题讨论】:

  • 我正在尝试解决同样的问题,您有解决方案吗?
  • 目前没有。也许,您可以投票赞成这个问题,以便它受到更多关注。我实际上离开了 cli,因此开始使用 angular 2 webpack starter
  • 我面临同样的问题,根据 github 上的讨论,看起来他们不会公开 webpack 配置,但我找不到任何解决方法

标签: webpack angular-cli


【解决方案1】:

尝试在 tsconfig.json 文件中使用 typescript compilerOptions paths 数组:

路径数组值与baseUrl相对。这是一个示例用法:

"compilerOptions": {
  "baseUrl": ".",
  "paths": {
    "@app/*": ["app/*"]
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-31
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 2017-05-21
    相关资源
    最近更新 更多