网页 综合 更新时间 2026-11-14 09:16:14

Configuration Types | webpack

自动蜘蛛 webpack.js.org 正文约 2109 字
Configuration Types | webpack
Besides exporting a single configuration object, there are a few more ways that cover other needs as well.
Eventually you will find the need to disambiguate in your webpack.config.js between development and production builds. There are multiple ways to do that. One option is to export a function from your webpack configuration instead of exporting an object. The function will be invoked with two arguments:
Webpack will run the function exported by the configuration file and wait for a Promise to be returned. Handy when you need to asynchronously load configuration variables.
It is possible to export multiple promises by wrapping them into Promise.all([/* Your promises */]).
Returning a Promise only works when using webpack via CLI. webpack() expects an object.
Instead of exporting a single configuration object/function, you may export multiple configurations (multiple functions are supported since webpack 3.1.0). When running webpack, all configurations are built. For instance, this is useful for bundling a library for multiple targets such as AMD and CommonJS:
If you pass a name to --config-name flag, webpack will only build that specific configuration.
In case you have a configuration that depends on the output of another configuration, you can specify a list of dependencies using the dependencies array.
In case you export multiple configurations, you can use the parallelism option on the configuration array to specify the maximum number of compilers that will compile in parallel.
Copyright OpenJS Foundation and webpack contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy
访问原文 返回搜索 https://webpack.js.org/configuration/configuration-types/
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。