【问题标题】:Add dependency to externals with "@" in the library name在库名称中使用“@”将依赖项添加到外部
【发布时间】:2020-01-26 01:22:44
【问题描述】:

我正在使用 ngx-build-plus 将我的 angular 元素与一些 webpack 额外配置打包在一起。在我的 webpack 额外配置中,我想排除名称以“@”开头的依赖项,例如 @angular/core。我知道可以通过将 @angular/core 映射到 ng.core 来排除它,但是对于我尝试使用的库,我认为我不能使用 ng 链接它,因为它不是角度依赖。我收到以下错误。

const webpack = require('webpack');
module.exports = {
  externals: {
    '@somelib/core': '@somelib/core' // Does not work
  }
};

来自 Terser 的 main-es2015.js 中的错误 意外字符“@”[main-es2015.js:101,17]

【问题讨论】:

    标签: javascript webpack webpack-2 webpack-4


    【解决方案1】:

    在添加 @blueprintjs/core 作为外部依赖项时,我遇到了同样的问题。 查看 webpack 生成的文件(在优化选项中使用 minimize: false ),问题似乎与导出有关:

    module.exports = @blueprintjs/core;

    将以下内容添加到我的 webpack.config 中:

        output: {
        // https://github.com/webpack/webpack/issues/1114
        libraryTarget: 'commonjs2'
      },
    

    允许正确配置 webpack 生成的 require:

    module.exports = require("@blueprintjs/core");

    查看github issue 并没有给我更多关于如何/为什么的信息,但我希望它会帮助其他人

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-04
      • 2018-09-14
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      相关资源
      最近更新 更多