Webpack
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: {},
}),
})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 be merged by webpack-merge.
chainWebpack
Type:
(config: WebpackChainConfig, isServer: boolean, isBuild: boolean) => voidDetails:
Edit the internal webpack config with webpack-chain.
This option accepts a function that will receive a
Configinstance that provided bywebpack-chainas the 1st argument anisServerflag as the 2nd argument and anisBuildflag as the 3rd argument.
devServerSetupMiddlewares
Type:
(middlewares: Middleware[], devServer: Server) => Middleware[]Details:
A hook to be called in
devServer.setupMiddlewaresof webpack.The arguments of the function are those of
devServer.setupMiddlewares.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
Unlike Vite, Webpack won't handle base for public files automatically. So if you change the base of your site, you'd better to use Base Helper when referencing an public image file.
Using with Default Theme
Default theme is using SASS as CSS pre-processor, so you might need to install sass-loader as a peer dependency to make it work with Webpack, especially when you are using pnpm.
