boolean: false
experiments
é
ç½®æ¯å¨ webpack 5 䏿¨åºï¼ç®çæ¯ä¸ºäºç»ç¨æ·èµè½å»å¼å¯å¹¶è¯ç¨ä¸äºå®éªçç¹æ§ã
Available options:
asyncWebAssembly
: Support the new WebAssembly according to the updated specification, it makes a WebAssembly module an async module. And it is enabled by default when experiments.futureDefaults
is set to true
.backCompat
buildHttp
cacheUnaffected
css
futureDefaults
layers
: Enable module and chunk layers.lazyCompilation
outputModule
syncWebAssembly
: Support the old WebAssembly like in webpack 4.topLevelAwait
: Support the Top Level Await Stage 3 proposal, it makes the module an async module when await
is used on the top-level. And it is enabled by default when experiments.futureDefaults
is set to true
.webpack.config.js
module.exports = {
//...
experiments: {
asyncWebAssembly: true,
buildHttp: true,
layers: true,
lazyCompilation: true,
outputModule: true,
syncWebAssembly: true,
topLevelAwait: true,
},
};
ä¸ºè®¸å¤ webpack 4 api å¯ç¨ååå ¼å®¹å±ï¼å¹¶ååºå¼ç¨è¦åã
boolean
module.exports = {
//...
experiments: {
backCompat: true,
},
};
When enabled, webpack can build remote resources that begin with the http(s):
protocol.
Type:
(string | RegExp | ((uri: string) => boolean))[]
A shortcut for experiments.buildHttp.allowedUris
.
HttpUriOptions
{
allowedUris: (string|RegExp|(uri: string) => boolean)[],
cacheLocation?: false | string,
frozen?: boolean,
lockfileLocation?: string,
upgrade?: boolean
}
Available: 5.49.0+
Example
// webpack.config.js
module.exports = {
//...
experiments: {
buildHttp: true,
},
};
// src/index.js
import pMap1 from 'https://cdn.skypack.dev/p-map';
// with `buildHttp` enabled, webpack will build pMap1 just like a regular local module
console.log(pMap1);
å 许ç URI å表ã
ç±»åï¼(string|RegExp|(uri: string) => boolean)[]
示ä¾
// webpack.config.js
module.exports = {
//...
experiments: {
buildHttp: {
allowedUris: [
'http://localhost:9990/',
'https://raw.githubusercontent.com/',
],
},
},
};
Define the location for caching remote resources.
Type
string
false
Example
// webpack.config.js
module.exports = {
//...
experiments: {
buildHttp: {
cacheLocation: false,
},
},
};
By default webpack would use <compiler-name.>webpack.lock.data/
for caching, but you can disable it by setting its value to false
.
Note that you should commit files under experiments.buildHttp.cacheLocation
into a version control system as no network requests will be made during the production
build.
Freeze the remote resources and lockfile. Any modification to the lockfile or resource contents will result in an error.
boolean
Define the location to store the lockfile.
string
By default webpack would generate a <compiler-name.>webpack.lock
file>. Make sure to commit it into a version control system. During the production
build, webpack will build those modules beginning with http(s):
protocol from the lockfile and caches under experiments.buildHttp.cacheLocation
.
æå®ç¨æ¥è·åè¿ç¨èµæºç代çæå¡å¨ã
string
é»è®¤æ
åµä¸ï¼webpack ä¼è®©ä»£çæå¡å¨ä½¿ç¨ http_proxy
ï¼ä¸åºå大å°åï¼ ç¯å¢åéå¼è·åè¿ç¨èµæºãç¶èï¼ä½ ä¹å¯ä»¥éè¿ proxy
é
置项æå®ã
æ£æµè¿ç¨èµæºçæ´æ¹å¹¶èªå¨å级ã
boolean
å¯ç¨åç CSS æ¯æã请注æè¯¥å®éªç¹æ§ä»å¤äºå¼åç¶æå¹¶ä¸å°ä¼å¨ webpack v6 ä¸é»è®¤å¯ç¨ï¼ä½ å¯ä»¥å¨ GitHub ä¸è·è¸ªè¿åº¦ã
boolean
Enable additional in-memory caching of modules which are unchanged and reference only unchanged modules.
boolean
Defaults to the value of futureDefaults
.
使ç¨ä¸ä¸ä¸ª webpack ä¸»çæ¬çé»è®¤å¼ï¼å¹¶å¨ä»»ä½æé®é¢çå°æ¹æ¾ç¤ºè¦åã
webpack.config.js
module.exports = {
//...
experiments: {
futureDefaults: true,
},
};
Compile entrypoints and dynamic import
s only when they are in use. It can be used for either Web or Node.js.
Type
boolean
object
{
// define a custom backend
backend?: ((
compiler: Compiler,
callback: (err?: Error, api?: BackendApi) => void
) => void)
| ((compiler: Compiler) => Promise<BackendApi>)
| {
/**
* A custom client.
*/
client?: string;
/**
* Specify where to listen to from the server.
*/
listen?: number | ListenOptions | ((server: typeof Server) => void);
/**
* Specify the protocol the client should use to connect to the server.
*/
protocol?: "http" | "https";
/**
* Specify how to create the server handling the EventSource requests.
*/
server?: ServerOptionsImport | ServerOptionsHttps | (() => typeof Server);
},
entries?: boolean,
imports?: boolean,
test?: string | RegExp | ((module: Module) => boolean)
}
backend
: Customize the backend.entries
: Enable lazy compilation for entries.imports
5.20.0+: Enable lazy compilation for dynamic imports.test
5.20.0+: Specify which imported modules should be lazily compiled.Available: 5.17.0+
Example 1:
module.exports = {
// â¦
experiments: {
lazyCompilation: true,
},
};
Example 2:
module.exports = {
// â¦
experiments: {
lazyCompilation: {
// disable lazy compilation for dynamic imports
imports: false,
// disable lazy compilation for entries
entries: false,
// do not lazily compile moduleB
test: (module) => !/moduleB/.test(module.nameForCondition()),
},
},
};
boolean
Once enabled, webpack will output ECMAScript module syntax whenever possible. For instance, import()
to load chunks, ESM exports to expose chunk data, among others.
module.exports = {
experiments: {
outputModule: true,
},
};