实验特性(experiments)

experiments

boolean: false

experiments 配置是在 webpack 5 中推出,目的是为了给用户赋能去开启并试用一些实验的特性。

可用的配置项:

  • syncWebAssembly: Support the old WebAssembly like in webpack 4
  • asyncWebAssembly: Support the new WebAssembly according to the updated specification, it makes a WebAssembly module an async module
  • topLevelAwait: Support the Top Level Await Stage 3 proposal, it makes the module an async module when await is used on the top-level
  • outputModule: enables the use of output.module configuration option and sets it to true. Enables the use of output.libraryTarget as 'module' and sets it to 'module'.
  • layers: Enable module and chunk layers.

webpack.config.js

module.exports = {
  //...
  experiments: {
    outputModule: true,
    syncWebAssembly: true,
    topLevelAwait: true,
    asyncWebAssembly: true,
    layers: true,
  },
};