英文:
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(), "inferno-helmet", {sharp: 'commonjs sharp'}]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论