Skip to content

Commit 21ae915

Browse files
Mister-Hopemeteorlxy
andauthoredMay 22, 2024··
feat(bundler-webpack): replace webpack-chain with webpack-5-chain (close #1503) (#1566)
Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
1 parent 3aed731 commit 21ae915

23 files changed

+47
-49
lines changed
 

‎packages/bundler-webpack/package.json

+1-1
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

+3-2
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

+1-1
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

+2-2
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

+1-1
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

+2-3
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

+1-1
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

+1-1
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

+1-1
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

+9-9
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
}

‎packages/bundler-webpack/src/config/handleModuleJs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createRequire } from 'node:module'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33
import type { WebpackBundlerOptions } from '../types.js'
44
import { resolveEsbuildJsxOptions } from './resolveEsbuildJsxOptions.js'
55

‎packages/bundler-webpack/src/config/handleModulePug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type Config from 'webpack-chain'
1+
import type Config from 'webpack-5-chain'
22

33
/**
44
* Set webpack module to handle pug files

‎packages/bundler-webpack/src/config/handleModuleStyles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createRequire } from 'node:module'
22
import autoprefixer from 'autoprefixer'
33
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
4-
import type Config from 'webpack-chain'
4+
import type Config from 'webpack-5-chain'
55
import type {
66
LessLoaderOptions,
77
LoaderOptions,

‎packages/bundler-webpack/src/config/handleModuleTs.ts

+1-1
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 { resolveEsbuildJsxOptions } from './resolveEsbuildJsxOptions.js'
55

66
const require = createRequire(import.meta.url)

‎packages/bundler-webpack/src/config/handleModuleVue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module'
22
import type { App } from '@vuepress/core'
33
import { VueLoaderPlugin } from 'vue-loader'
44
import type { VueLoaderOptions } from 'vue-loader'
5-
import type Config from 'webpack-chain'
5+
import type Config from 'webpack-5-chain'
66
import type { WebpackBundlerOptions } from '../types.js'
77

88
const require = createRequire(import.meta.url)

‎packages/bundler-webpack/src/config/handleNode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type Config from 'webpack-chain'
1+
import type Config from 'webpack-5-chain'
22

33
/**
44
* Set webpack node config

‎packages/bundler-webpack/src/config/handleOtherOptions.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createRequire } from 'node:module'
22
import type { App } from '@vuepress/core'
3-
import type { Configuration } from 'webpack'
4-
import type Config from 'webpack-chain'
3+
import type Config from 'webpack-5-chain'
54

65
const require = createRequire(import.meta.url)
76

@@ -22,12 +21,12 @@ export const handleOtherOptions = ({
2221
isServer: boolean
2322
}): void => {
2423
// set infrastructureLogging options
25-
config.set('infrastructureLogging', {
24+
config.infrastructureLogging({
2625
level: app.env.isDebug ? 'info' : 'error',
27-
} as Configuration['infrastructureLogging'])
26+
})
2827

2928
// set cache options
30-
config.set('cache', {
29+
config.cache({
3130
type: 'filesystem',
3231
cacheDirectory: app.dir.cache(),
3332
version: JSON.stringify({
@@ -40,5 +39,5 @@ export const handleOtherOptions = ({
4039
'vue-loader': require('vue-loader/package.json').version,
4140
'webpack': require('webpack/package.json').version,
4241
}),
43-
} as Configuration['cache'])
42+
})
4443
}

‎packages/bundler-webpack/src/config/handlePluginDefine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { App } from '@vuepress/core'
22
import webpack from 'webpack'
3-
import type Config from 'webpack-chain'
3+
import type Config from 'webpack-5-chain'
44

55
/**
66
* Set webpack DefinePlugin

‎packages/bundler-webpack/src/config/handleResolve.ts

+1-1
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 resolve

‎packages/bundler-webpack/src/dev/createDevConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { App } from '@vuepress/core'
22
import HtmlPlugin from 'html-webpack-plugin'
33
import webpack from 'webpack'
4-
import type Config from 'webpack-chain'
4+
import type Config from 'webpack-5-chain'
55
import { createClientBaseConfig } from '../config/index.js'
66
import type { WebpackBundlerOptions } from '../types.js'
77

‎packages/bundler-webpack/src/resolveWebpackConfig.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Configuration } from 'webpack'
2-
import type Config from 'webpack-chain'
2+
import type Config from 'webpack-5-chain'
33
import { merge } from 'webpack-merge'
44
import type { WebpackBundlerOptions } from './types.js'
55

@@ -17,7 +17,7 @@ export const resolveWebpackConfig = ({
1717
// allow modifying webpack config via `chainWebpack`
1818
options.chainWebpack?.(config, isServer, isBuild)
1919

20-
// generate webpack config from webpack-chain
20+
// generate webpack config from webpack-5-chain
2121
const webpackConfig = config.toConfig()
2222

2323
// allow modifying webpack config via `configureWebpack`

‎packages/bundler-webpack/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
LoaderContext,
44
Configuration as WebpackConfiguration,
55
} from 'webpack'
6-
import type WebpackChainConfig from 'webpack-chain'
6+
import type WebpackChainConfig from 'webpack-5-chain'
77
import type WebpackDevServer from 'webpack-dev-server'
88

99
export type {
@@ -27,7 +27,7 @@ export interface WebpackBundlerOptions {
2727
) => WebpackConfiguration | void
2828

2929
/**
30-
* use webpack-chain to set webpack config
30+
* use webpack-5-chain to set webpack config
3131
*/
3232
chainWebpack?: (
3333
config: WebpackChainConfig,

‎pnpm-lock.yaml

+7-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.