Webpack配置外部如何混合数组和对象语法

huangapple go评论64阅读模式
英文:

Webpack config externals how to mix array and object syntax

问题

Currently I have a webpack config with the externals set like so:

externals: [nodeExternals(), "inferno-helmet"]

I'm trying to add the sharp image processing library to my project. According to the docs, in order to work with a project that uses webpack, externals must be set like so:

externals: {
  'sharp': 'commonjs sharp'
}

I figure for sharp and inferno-helmet, the externals would look like this:

externals: {
    'sharp': 'commonjs sharp',
    'inferno-helmet': 'inferno-helmet',
    // ?
}

I don't understand how to properly use node externals with this syntax. The README for the webpack-node-externals only shows examples of passing an array to externals. How can I include all three of the node externals, inferno-helmet, and sharp in the externals?

英文:

Currently I have a webpack config with the externals set like so:

externals: [nodeExternals(), "inferno-helmet"]

I'm trying to add the sharp image processing library to my project. According to the docs, in order to work with a project that uses webpack, externals must be set like so:

externals: {
  'sharp': 'commonjs sharp'
}

I figure for sharp and inferno-helmet, the externals would look like this:

externals: {
    'sharp': 'commonjs sharp',
    'inferno-helmet': 'inferno-helmet',
    // ?
}

I don't understand how to properly use node externals with this syntax. The README for the webpack-node-externals only shows examples of passing an array to externals. How can I include all three of the node externals, inferno-helmet, and sharp in the externals?

答案1

得分: 1

这是一个有效的答案:```javascript
externals: [nodeExternals(), "inferno-helmet", {sharp: 'commonjs sharp'}]


<details>
<summary>英文:</summary>

It turns out this is a valid answer:
```javascript
externals: [nodeExternals(), &quot;inferno-helmet&quot;, {sharp: &#39;commonjs sharp&#39;}]

huangapple
  • 本文由 发表于 2023年5月6日 23:53:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定