English
Webpack
Webpack bundler is provided by @vuepress/bundler-webpack package.
Usage
Install the bundler package:
npm i -D @vuepress/bundler-webpack@nextSpecify the bundler option in your config file:
import { webpackBundler } from '@vuepress/bundler-webpack'
import { defineUserConfig } from 'vuepress'
export default defineUserConfig({
bundler: webpackBundler({
postcss: {},
vue: {},
}),
})Exports
webpackBundler
Type:
(options?: WebpackBundlerOptions) => BundlerDetails:
Create a webpack bundler instance.
webpackMergeConfig
Type:
(configA: WebpackConfiguration, configB: WebpackConfiguration) => WebpackConfigurationDetails:
Merge two webpack config objects, provided by webpack-merge.
Exported types
The package re-exports the types of its options and the underlying tools:
WebpackBundlerOptionsWebpackConfiguration(fromwebpack)WebpackChainConfig(fromwebpack-v5-chain)WebpackDevServerConfiguration(fromwebpack-dev-server)VueLoaderOptions,PostcssLoaderOptions,StylusLoaderOptions,SassLoaderOptions,LessLoaderOptions
Tips
In webpack-dev-server v6, the configuration type is no longer exposed through the WebpackDevServer.Configuration namespace. @vuepress/bundler-webpack now re-exports it as the named WebpackDevServerConfiguration type (the WebpackDevServer type is still exported as well), and devServerSetupMiddlewares uses WebpackDevServerConfiguration.
Options
configureWebpack
Type:
(config: WebpackConfiguration, isServer: boolean, isBuild: boolean) => WebpackConfiguration | voidDetails:
Edit the internal webpack config.
This option accepts a function that will receive a webpack config object as the 1st argument, an
isServerflag as the 2nd argument and anisBuildflag as the 3rd argument. You can either mutate the config directly, or return an object to replace the webpack config object.If you need to merge configs instead of replacing them, use webpackMergeConfig.
chainWebpack
Type:
(config: WebpackChainConfig, isServer: boolean, isBuild: boolean) => voidDetails:
Edit the internal webpack config with webpack-v5-chain.
This option accepts a function that will receive a
Configinstance that provided bywebpack-v5-chainas the 1st argument anisServerflag as the 2nd argument and anisBuildflag as the 3rd argument.
devServerSetupMiddlewares
Type:
WebpackDevServerConfiguration['setupMiddlewares']Details:
A hook to be called in
devServer.setupMiddlewaresof webpack-dev-server.The arguments of the function are those of
devServer.setupMiddlewares. TheWebpackDevServerConfigurationtype is re-exported by@vuepress/bundler-webpack.Also see:
vue
Type:
VueLoaderOptionsDetails:
Options for
vue-loader.Also see:
postcss
Type:
PostcssLoaderOptionsDetails:
Options for
postcss-loader.Also see:
stylus
Type:
StylusLoaderOptionsDetails:
Options for
stylus-loader.Also see:
scss
Type:
SassLoaderOptionsDetails:
Options for
sass-loaderfor.scssfiles.Also see:
sass
Type:
SassLoaderOptionsDetails:
Options for
sass-loaderfor.sassfiles.Also see:
less
Type:
LessLoaderOptionsDetails:
Options for
less-loader.Also see:
evergreen
Type:
booleanDefault:
trueDetails:
Set to
trueif you are only targeting evergreen browsers. This will disable some transpilation and polyfills, and result in faster builds and smaller files.
FAQ
Referencing Public Files after Changing base
VuePress prepends base to absolute asset paths in Markdown automatically when using the Webpack and Rspack bundlers, so public files referenced from Markdown keep working after you change the base of your site. If you create URLs at runtime (for example, in a Vue component), use Base Helper.
Using with SASS-based Themes
The default theme uses plain CSS, so it does not require any SASS setup. If you use a theme that relies on SASS as CSS pre-processor — for example, the classic theme (@vuepress/theme-classic) — you might need to install sass-loader as a peer dependency to make it work with Webpack (and Rspack), especially when you are using pnpm.
