网页
综合
更新时间 2026-11-14 16:19:16
Target | webpack
自动蜘蛛
webpack.js.org
正文约 3647 字
Webpack can compile for multiple environments or targets. To understand what a target is in detail, read through the targets concept page.
string string[] false
Instructs webpack to generate runtime code for a specific environment. Note that webpack runtime code is not the same as the user code you write, you should transpile that code with transpilers like Babel if you want to target specific environments, e.g, you have arrow functions in source code and want to run the bundled code in ES5 environments. Webpack won't transpile them automatically with a target configured.
Defaults to 'browserslist' or to 'web' when no browserslist configuration was found.
The following string values are supported via WebpackOptionsApply:
For example, when the target is set to "electron-main", webpack includes multiple electron specific variables.
A version of node or electron may be optionally specified. This is denoted by the [[X].Y] in the table above.
It helps determinate ES-features that may be used to generate a runtime-code (all the chunks and modules are wrapped by runtime code).
If a project has a browserslist config, then webpack will use it for:
Supported browserslist values:
A single preset that combines the web, web worker, node, electron and nwjs platforms, leaving each platform flag neutral so the bundle adapts at runtime instead of being locked to one environment. It is a convenient replacement for hand-writing target: ["web", "node"], and it always outputs ECMAScript modules. output.module defaults to true for this target.
Notes for universal builds:
Compile for Bun. The bundle is emitted as ECMAScript modules (output.module defaults to true), and Bun's own bun:* modules together with the Node.js built-in modules Bun provides are externalized instead of being bundled.
Compile for Deno. The bundle is emitted as ECMAScript modules (output.module defaults to true). Node.js built-ins are resolved through the node: specifier Deno requires, and Deno's own import protocols (npm:, jsr:, node: and http(s):// URLs) are kept external so the runtime loads them. A version may be specified, for example deno2 or deno1.40.
When multiple targets are passed, then common subset of features will be used:
Webpack will generate a runtime code for web platform and will use only ES5 features.
You can also combine platform targets to build universal code that runs in multiple environments:
Webpack will generate runtime code that works in both browser and Node.js environments.
Set target to false if none of the predefined targets from the list above meet your needs, no plugins will be applied.
Without a target webpack cannot infer the target-dependent defaults, so output.chunkFormat must be set explicitly (and usually output.chunkLoading and output.environment as well); otherwise the build fails with "Chunk format can't be selected by default when no target is specified".
Or you can apply specific plugins you want:
When no information about the target or the environment features is provided, then ES2015 will be used.
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
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。