【问题标题】:How can I build for cdn with webpack?如何使用 webpack 为 cdn 构建?
【发布时间】:2021-02-08 09:30:17
【问题描述】:

我创建了一个这样的模块:

export default () => console.log('hello my_module~!')

webpack.config.js文件中的设置如下:

module.exports = {
  // ...
  output: {
    // ...
    library: 'hello',
    libraryTarget: 'var'
  }
}

而在html文件中,脚本代码为:

<script src="/output_my_module.js"></script>
<script>
  hello.default(); // yea~ It's work!!
</script>

但我想要的方式如下:

hello(); // I want use like this.

我该怎么办?我读了webpack's doc,但找不到方法。 (可能是因为我英文不好所以错过了……)

【问题讨论】:

    标签: javascript node.js npm webpack


    【解决方案1】:

    您应该将libraryExport 放入您的配置中。

      library: 'hello',
      libraryTarget: 'var',
      libraryExport: 'default'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 2017-10-29
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 2019-10-31
      相关资源
      最近更新 更多