webpack can compile for multiple environments or targets. To understand what a target
is in detail, read through the targets concept page.
target
string | function(compiler)
Intructs webpack to target a specific environment.
string
The following string values are supported via WebpackOptionsApply
:
async-node
fs
and vm
to load chunks asynchronously)
atom
electron-main
electron
electron-main
electron-main
electron-renderer
JsonpTemplatePlugin
, FunctionModulePlugin
for browser environments and NodeTargetPlugin
and ExternalsPlugin
for CommonJS and Electron built-in modules.
node
require
to load chunks)
node-webkit
nw.gui
(experimental)
web
webworker
For example, when the target
is set to "electron"
, webpack includes multiple electron specific variables. For more information on which templates and externals are used, you can refer to webpack's source code.
function
If a function is passed, then it will be called with the compiler as a parameter. Set it to a function if none of the predefined targets from the list above meet your needs.
For example, if you don't want any of the plugins they applied:
const options = {
target: () => undefined
};
Or you can apply specific plugins you want:
const webpack = require("webpack");
const options = {
target: (compiler) => {
compiler.apply(
new webpack.JsonpTemplatePlugin(options.output),
new webpack.LoaderTargetPlugin("web")
);
}
};