Skip to content

Commit

Permalink
refactor(bundler-webpack): improve build dir structure and e2e script…
Browse files Browse the repository at this point in the history
…s of webpack
  • Loading branch information
meteorlxy committed Sep 9, 2024
1 parent 240e7fe commit 47edee1
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 22 deletions.
8 changes: 4 additions & 4 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"type": "module",
"scripts": {
"docs:build": "vuepress build docs --clean-cache --clean-temp",
"docs:build-webpack": "cross-env E2E_BUNDLER=webpack pnpm docs:build",
"docs:build:webpack": "cross-env E2E_BUNDLER=webpack pnpm docs:build",
"docs:clean": "rimraf docs/.vuepress/.temp docs/.vuepress/.cache docs/.vuepress/dist",
"docs:dev": "vuepress dev docs --clean-cache --clean-temp",
"docs:dev-webpack": "cross-env E2E_BUNDLER=webpack pnpm docs:dev",
"docs:dev:webpack": "cross-env E2E_BUNDLER=webpack pnpm docs:dev",
"docs:serve": "anywhere -s -h localhost -p 9080 -d docs/.vuepress/dist",
"e2e:build": "cross-env E2E_COMMAND=build playwright test",
"e2e:build-webpack": "cross-env E2E_COMMAND=build E2E_BUNDLER=webpack playwright test",
"e2e:build:webpack": "cross-env E2E_COMMAND=build E2E_BUNDLER=webpack playwright test",
"e2e:dev": "cross-env E2E_COMMAND=dev playwright test",
"e2e:dev-webpack": "cross-env E2E_COMMAND=dev E2E_BUNDLER=webpack playwright test"
"e2e:dev:webpack": "cross-env E2E_COMMAND=dev E2E_BUNDLER=webpack playwright test"
},
"dependencies": {
"@vuepress-e2e/conditional-exports": "file:./modules/conditional-exports",
Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig, devices } from '@playwright/test'
import { BASE, BUNDLER, IS_CI, IS_DEV } from './utils/env'

const COMMAND_PART1 = IS_DEV ? 'docs:dev' : 'docs:build'
const COMMAND_PART2 = BUNDLER === 'vite' ? '' : `-${BUNDLER}`
const COMMAND_PART2 = BUNDLER === 'vite' ? '' : `:${BUNDLER}`
const COMMAND_PART3 = IS_DEV ? '' : ' && pnpm docs:serve'

export default defineConfig({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"release:version": "bumpp -r --execute=\"pnpm release:changelog\" --commit \"build: publish v%s\" --all",
"test": "pnpm test:unit && pnpm test:e2e",
"test:e2e": "pnpm --filter e2e e2e:dev && pnpm --filter e2e e2e:build",
"test:e2e:webpack": "pnpm --filter e2e e2e:dev:webpack && pnpm --filter e2e e2e:build:webpack",
"test:unit": "vitest run",
"test:unit:cov": "vitest run --coverage"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { createServerConfig } from './createServerConfig.js'
import { renderPage } from './renderPage.js'
import { resolveClientManifestMeta } from './resolveClientManifestMeta.js'
import type { ClientManifest } from './ssr/index.js'
import type { ClientManifest } from './types.js'

const log = debug('vuepress:bundler-webpack/build')

Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/build/createClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin'
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'
import { createClientPlugin } from './createClientPlugin.js'

const require = createRequire(import.meta.url)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { fs } from '@vuepress/utils'
import type { StatsModule, WebpackPluginInstance } from 'webpack'
import { isCSS, isJS } from './utils.js'
import type { ClientManifest } from './types.js'

export interface ClientManifest {
all: string[]
initial: string[]
async: string[]
modules: Record<string, number[]>
}
const isJS = (file: string): boolean => /\.js(\?[^.]+)?$/.test(file)

const isCSS = (file: string): boolean => /\.css(\?[^.]+)?$/.test(file)

/**
* Vuepress client plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { resolveFileMeta } from './resolveFileMeta.js'
import type { ClientManifest } from './ssr/index.js'
import type { FileMeta, ModuleFilesMetaMap } from './types.js'
import type { ClientManifest, FileMeta, ModuleFilesMetaMap } from './types.js'

/**
* Resolve files meta from clientManifest
Expand Down
2 changes: 0 additions & 2 deletions packages/bundler-webpack/src/build/ssr/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/bundler-webpack/src/build/ssr/utils.ts

This file was deleted.

10 changes: 10 additions & 0 deletions packages/bundler-webpack/src/build/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ export type FileMetaType = '' | 'font' | 'image' | 'script' | 'style'
* A "module request" to "client files meta" key-value map
*/
export type ModuleFilesMetaMap = Record<string, FileMeta[]>

/**
* Client manifest that collected from webpack stats
*/
export interface ClientManifest {
all: string[]
initial: string[]
async: string[]
modules: Record<string, number[]>
}
2 changes: 1 addition & 1 deletion packages/bundler-webpack/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig([
{
...shared,
entry: {
'vuepress-ssr-loader': './src/build/ssr/vuepressSsrLoader.cts',
'vuepress-ssr-loader': './src/loaders/vuepressSsrLoader.cts',
},
format: ['cjs'],
},
Expand Down

0 comments on commit 47edee1

Please sign in to comment.