Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bundler-webpack): replace webpack-chain with webpack-5-chain (close #1503) #1566

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bundler-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"vue-loader": "^17.4.2",
"vue-router": "^4.3.2",
"webpack": "^5.91.0",
"webpack-chain": "^6.5.1",
"webpack-5-chain": "^8.0.2",
"webpack-dev-server": "^5.0.4",
"webpack-merge": "^5.10.0"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler-webpack/src/build/createClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { App } from '@vuepress/core'
import { fs } from '@vuepress/utils'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import type { CssModule } from 'mini-css-extract-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import { createClientBaseConfig } from '../config/index.js'
import type { WebpackBundlerOptions } from '../types.js'
import { createClientPlugin } from './ssr/index.js'
Expand Down Expand Up @@ -65,7 +66,7 @@ export const createClientConfig = async (
styles: {
idHint: 'styles',
// necessary to ensure async chunks are also extracted
test: (m) => /css\/mini-extract/.test(m.type),
test: (m: CssModule) => /css\/mini-extract/.test(m.type),
chunks: 'all',
enforce: true,
reuseExistingChunk: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/build/createServerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import { createBaseConfig } from '../config/index.js'
import type { WebpackBundlerOptions } from '../types.js'

Expand Down
4 changes: 2 additions & 2 deletions packages/bundler-webpack/src/config/createBaseConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import Config from 'webpack-chain'
import Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'
import { handleDevtool } from './handleDevtool.js'
import { handleEntry } from './handleEntry.js'
Expand All @@ -21,7 +21,7 @@ export const createBaseConfig = async ({
isBuild: boolean
isServer: boolean
}): Promise<Config> => {
// create new webpack-chain config
// create new webpack-5-chain config
const config = new Config()

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'
import { createBaseConfig } from './createBaseConfig.js'

Expand Down
5 changes: 2 additions & 3 deletions packages/bundler-webpack/src/config/handleDevtool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack devtool
Expand All @@ -18,7 +18,6 @@ export const handleDevtool = ({
config.devtool('source-map')
} else if (!isBuild) {
// only enable eval-source-map in dev mode
// TODO: remove type assertion when webpack-chain updates its types for webpack 5
config.devtool('eval-cheap-module-source-map' as Config.DevTool)
config.devtool('eval-cheap-module-source-map')
}
}
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleEntry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { App } from '@vuepress/core'
import { fs } from '@vuepress/utils'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack entry
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleMode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack mode
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'
import { handleModuleAssets } from './handleModuleAssets.js'
import { handleModuleJs } from './handleModuleJs.js'
Expand Down
18 changes: 9 additions & 9 deletions packages/bundler-webpack/src/config/handleModuleAssets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

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

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

// media
config.module
.rule('media')
.test(/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/)
.type('asset/resource' as any)
.set('generator', {
.type('asset/resource')
.generator({
filename: 'assets/media/[name].[contenthash:8][ext]',
})

// fonts
config.module
.rule('fonts')
.test(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i)
.type('asset/resource' as any)
.set('generator', {
.type('asset/resource')
.generator({
filename: 'assets/fonts/[name].[contenthash:8][ext]',
})
}
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModuleJs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRequire } from 'node:module'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'
import { resolveEsbuildJsxOptions } from './resolveEsbuildJsxOptions.js'

Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModulePug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack module to handle pug files
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModuleStyles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRequire } from 'node:module'
import autoprefixer from 'autoprefixer'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import type {
LessLoaderOptions,
LoaderOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModuleTs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import { resolveEsbuildJsxOptions } from './resolveEsbuildJsxOptions.js'

const require = createRequire(import.meta.url)
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModuleVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import { VueLoaderPlugin } from 'vue-loader'
import type { VueLoaderOptions } from 'vue-loader'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'

const require = createRequire(import.meta.url)
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack node config
Expand Down
11 changes: 5 additions & 6 deletions packages/bundler-webpack/src/config/handleOtherOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import type { Configuration } from 'webpack'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

const require = createRequire(import.meta.url)

Expand All @@ -22,12 +21,12 @@ export const handleOtherOptions = ({
isServer: boolean
}): void => {
// set infrastructureLogging options
config.set('infrastructureLogging', {
config.infrastructureLogging({
level: app.env.isDebug ? 'info' : 'error',
} as Configuration['infrastructureLogging'])
})

// set cache options
config.set('cache', {
config.cache({
type: 'filesystem',
cacheDirectory: app.dir.cache(),
version: JSON.stringify({
Expand All @@ -40,5 +39,5 @@ export const handleOtherOptions = ({
'vue-loader': require('vue-loader/package.json').version,
'webpack': require('webpack/package.json').version,
}),
} as Configuration['cache'])
})
}
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handlePluginDefine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { App } from '@vuepress/core'
import webpack from 'webpack'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack DefinePlugin
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleResolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'

/**
* Set webpack resolve
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/dev/createDevConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { App } from '@vuepress/core'
import HtmlPlugin from 'html-webpack-plugin'
import webpack from 'webpack'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import { createClientBaseConfig } from '../config/index.js'
import type { WebpackBundlerOptions } from '../types.js'

Expand Down
4 changes: 2 additions & 2 deletions packages/bundler-webpack/src/resolveWebpackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Configuration } from 'webpack'
import type Config from 'webpack-chain'
import type Config from 'webpack-5-chain'
import { merge } from 'webpack-merge'
import type { WebpackBundlerOptions } from './types.js'

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

// generate webpack config from webpack-chain
// generate webpack config from webpack-5-chain
const webpackConfig = config.toConfig()

// allow modifying webpack config via `configureWebpack`
Expand Down
4 changes: 2 additions & 2 deletions packages/bundler-webpack/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
LoaderContext,
Configuration as WebpackConfiguration,
} from 'webpack'
import type WebpackChainConfig from 'webpack-chain'
import type WebpackChainConfig from 'webpack-5-chain'
import type WebpackDevServer from 'webpack-dev-server'

export type {
Expand All @@ -27,7 +27,7 @@ export interface WebpackBundlerOptions {
) => WebpackConfiguration | void

/**
* use webpack-chain to set webpack config
* use webpack-5-chain to set webpack config
*/
chainWebpack?: (
config: WebpackChainConfig,
Expand Down
15 changes: 7 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading