Skip to content

Commit 21ae915

Browse files
feat(bundler-webpack): replace webpack-chain with webpack-5-chain (close #1503) (#1566)
Co-authored-by: meteorlxy <[email protected]>
1 parent 3aed731 commit 21ae915

23 files changed

+47
-49
lines changed

packages/bundler-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"vue-loader": "^17.4.2",
6060
"vue-router": "^4.3.2",
6161
"webpack": "^5.91.0",
62-
"webpack-chain": "^6.5.1",
62+
"webpack-5-chain": "^8.0.2",
6363
"webpack-dev-server": "^5.0.4",
6464
"webpack-merge": "^5.10.0"
6565
},

packages/bundler-webpack/src/build/createClientConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import type { App } from '@vuepress/core'
33
import { fs } from '@vuepress/utils'
44
import CopyWebpackPlugin from 'copy-webpack-plugin'
55
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
6+
import type { CssModule } from 'mini-css-extract-plugin'
67
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
7-
import type Config from 'webpack-chain'
8+
import type Config from 'webpack-5-chain'
89
import { createClientBaseConfig } from '../config/index.js'
910
import type { WebpackBundlerOptions } from '../types.js'
1011
import { createClientPlugin } from './ssr/index.js'
@@ -65,7 +66,7 @@ export const createClientConfig = async (
6566
styles: {
6667
idHint: 'styles',
6768
// necessary to ensure async chunks are also extracted
68-
test: (m) => /css\/mini-extract/.test(m.type),
69+
test: (m: CssModule) => /css\/mini-extract/.test(m.type),
6970
chunks: 'all',
7071
enforce: true,
7172
reuseExistingChunk: true,

packages/bundler-webpack/src/build/createServerConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRequire } from 'node:module'
22
import type { App } from '@vuepress/core'
3-
import type Config from 'webpack-chain'
3+
import type Config from 'webpack-5-chain'
44
import { createBaseConfig } from '../config/index.js'
55
import type { WebpackBundlerOptions } from '../types.js'
66

packages/bundler-webpack/src/config/createBaseConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App } from '@vuepress/core'
2-
import Config from 'webpack-chain'
2+
import Config from 'webpack-5-chain'
33
import type { WebpackBundlerOptions } from '../types.js'
44
import { handleDevtool } from './handleDevtool.js'
55
import { handleEntry } from './handleEntry.js'
@@ -21,7 +21,7 @@ export const createBaseConfig = async ({
2121
isBuild: boolean
2222
isServer: boolean
2323
}): Promise<Config> => {
24-
// create new webpack-chain config
24+
// create new webpack-5-chain config
2525
const config = new Config()
2626

2727
/**

packages/bundler-webpack/src/config/createClientBaseConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App } from '@vuepress/core'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33
import type { WebpackBundlerOptions } from '../types.js'
44
import { createBaseConfig } from './createBaseConfig.js'
55

packages/bundler-webpack/src/config/handleDevtool.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App } from '@vuepress/core'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33

44
/**
55
* Set webpack devtool
@@ -18,7 +18,6 @@ export const handleDevtool = ({
1818
config.devtool('source-map')
1919
} else if (!isBuild) {
2020
// only enable eval-source-map in dev mode
21-
// TODO: remove type assertion when webpack-chain updates its types for webpack 5
22-
config.devtool('eval-cheap-module-source-map' as Config.DevTool)
21+
config.devtool('eval-cheap-module-source-map')
2322
}
2423
}

packages/bundler-webpack/src/config/handleEntry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { App } from '@vuepress/core'
22
import { fs } from '@vuepress/utils'
3-
import type Config from 'webpack-chain'
3+
import type Config from 'webpack-5-chain'
44

55
/**
66
* Set webpack entry

packages/bundler-webpack/src/config/handleMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App } from '@vuepress/core'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33

44
/**
55
* Set webpack mode

packages/bundler-webpack/src/config/handleModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App } from '@vuepress/core'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33
import type { WebpackBundlerOptions } from '../types.js'
44
import { handleModuleAssets } from './handleModuleAssets.js'
55
import { handleModuleJs } from './handleModuleJs.js'

packages/bundler-webpack/src/config/handleModuleAssets.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App } from '@vuepress/core'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33

44
/**
55
* Set webpack config to handle assets files
@@ -15,8 +15,8 @@ export const handleModuleAssets = ({
1515
config.module
1616
.rule('images')
1717
.test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
18-
.type('asset' as any)
19-
.set('generator', {
18+
.type('asset')
19+
.generator({
2020
filename: 'assets/img/[name].[contenthash:8][ext]',
2121
})
2222

@@ -26,26 +26,26 @@ export const handleModuleAssets = ({
2626
config.module
2727
.rule('svg')
2828
.test(/\.(svg)(\?.*)?$/)
29-
.type('asset/resource' as any)
30-
.set('generator', {
29+
.type('asset/resource')
30+
.generator({
3131
filename: 'assets/img/[name].[contenthash:8][ext]',
3232
})
3333

3434
// media
3535
config.module
3636
.rule('media')
3737
.test(/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/)
38-
.type('asset/resource' as any)
39-
.set('generator', {
38+
.type('asset/resource')
39+
.generator({
4040
filename: 'assets/media/[name].[contenthash:8][ext]',
4141
})
4242

4343
// fonts
4444
config.module
4545
.rule('fonts')
4646
.test(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i)
47-
.type('asset/resource' as any)
48-
.set('generator', {
47+
.type('asset/resource')
48+
.generator({
4949
filename: 'assets/fonts/[name].[contenthash:8][ext]',
5050
})
5151
}

0 commit comments

Comments
 (0)