Skip to content

Commit 31ac4c9

Browse files
authored
Merge branch 'main' into resolve-route
2 parents 05e88e9 + 5615fd3 commit 31ac4c9

27 files changed

+265
-660
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"eslint-config-vuepress": "^4.10.1",
4444
"eslint-config-vuepress-typescript": "^4.10.1",
4545
"husky": "^9.0.11",
46-
"lint-staged": "^15.2.2",
46+
"lint-staged": "^15.2.4",
4747
"prettier": "^3.2.5",
4848
"prettier-config-vuepress": "^4.4.0",
4949
"rimraf": "^5.0.7",
@@ -55,7 +55,7 @@
5555
"vitest": "^1.6.0",
5656
"vue-tsc": "^2.0.19"
5757
},
58-
"packageManager": "[email protected].1",
58+
"packageManager": "[email protected].2",
5959
"engines": {
6060
"node": ">=18.16.0"
6161
}

packages/bundler-webpack/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"esbuild-loader": "~4.1.0",
5151
"express": "^4.19.2",
5252
"html-webpack-plugin": "^5.6.0",
53-
"lightningcss": "^1.24.1",
53+
"lightningcss": "^1.25.0",
5454
"mini-css-extract-plugin": "^2.9.0",
5555
"postcss": "^8.4.38",
5656
"postcss-loader": "^8.1.1",
@@ -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/build/ssr/createClientPlugin.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { fs } from '@vuepress/utils'
2-
import type { WebpackPluginInstance } from 'webpack'
3-
import type { FnModules, StatsToJsonOutput } from '../../types.webpack.js'
2+
import type { StatsModule, WebpackPluginInstance } from 'webpack'
43
import { isCSS, isJS } from './utils.js'
54

65
export interface ClientManifest {
@@ -29,17 +28,17 @@ export const createClientPlugin = (
2928
modules = [],
3029
entrypoints = {},
3130
chunks = [],
32-
}: StatsToJsonOutput = compilation
33-
.getStats()
34-
.toJson() as unknown as StatsToJsonOutput
31+
} = compilation.getStats().toJson()
3532

3633
// get all files
3734
const allFiles = assets.map((a) => a.name)
3835

3936
// get initial entry files
4037
const initialFiles = Object.keys(entrypoints)
41-
.map((name) => entrypoints[name].assets.map((item) => item.name))
42-
.reduce((assets, all) => all.concat(assets), [])
38+
.flatMap(
39+
(name) =>
40+
entrypoints[name].assets?.map((item) => item.name) ?? [],
41+
)
4342
.filter((file) => isJS(file) || isCSS(file))
4443

4544
// get files that should be loaded asynchronously
@@ -51,18 +50,19 @@ export const createClientPlugin = (
5150

5251
// get asset modules
5352
const assetModules = modules.filter(
54-
(m): m is FnModules & Required<Pick<FnModules, 'assets'>> =>
55-
!!(m.assets && m.assets.length),
53+
(m): m is StatsModule & Required<Pick<StatsModule, 'assets'>> =>
54+
Boolean(m.assets?.length),
5655
)
5756

5857
// get modules for client manifest
5958
const manifestModules: ClientManifest['modules'] = {}
6059

61-
const fileToIndex = (file: string): number => allFiles.indexOf(file)
60+
const fileToIndex = (file: number | string): number =>
61+
allFiles.indexOf(file.toString())
6262

6363
modules.forEach((m) => {
6464
// ignore modules duplicated in multiple chunks
65-
if (m.chunks.length !== 1) {
65+
if (m.chunks?.length !== 1) {
6666
return
6767
}
6868

@@ -75,21 +75,21 @@ export const createClientPlugin = (
7575

7676
// remove appended hash of module identifier
7777
// which is the request string of the module
78-
const request = m.identifier.replace(/\|\w+$/, '')
78+
const request = m.identifier?.replace(/\|\w+$/, '')
7979

8080
// get chunk files index
8181
const files = [...chunk.files.map(fileToIndex)]
8282

8383
// find all asset modules associated with the same chunk
8484
assetModules.forEach((m) => {
85-
if (m.chunks.some((id) => id === cid)) {
85+
if (m.chunks?.some((id) => id === cid)) {
8686
// get asset files
8787
files.push(...m.assets.map(fileToIndex))
8888
}
8989
})
9090

9191
// map the module request to files index
92-
manifestModules[request] = files
92+
if (request) manifestModules[request] = files
9393
})
9494

9595
// generate client manifest json file

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`

0 commit comments

Comments
 (0)