refactor: remove temp page files and load page component via bundler (close #1584)#1606
refactor: remove temp page files and load page component via bundler (close #1584)#1606
Conversation
ca281d1 to
b4ff6a7
Compare
Pull Request Test Coverage Report for Build 22883246688Details
💛 - Coveralls |
There was a problem hiding this comment.
The ecosystem and downstream plugins need a new option, I would design it as onPageUpdate
Technically speaking, a plugin can get all pages in onInitialized lifecycle, but when a new page is added, changed or removed in devServer, a plugin cannot subscribe because page generating and extendsPage hook are all async, we are watching the temp files before this PR, but this workaround no longer works now.
So to let the plugin work well, the onPageUpdate should be:
onPageUpdated(app: App, type: 'add' | 'change' | 'remove', oldPage: Page | null, newPage: Page | null)Or we can split it into 3 subscriber:
onPageAdded(app: App, newPage: Page | null)
onPageChanged(app: App, oldPage: Page, newPage: Page)
onPageRemoved(app: App, oldPage: Page)25a3396 to
5488138
Compare
24183b7 to
b091364
Compare
This reverts commit c6bd7c3.
There was a problem hiding this comment.
Pull request overview
This PR refactors VuePress page compilation so that page components are loaded/compiled directly by the active bundler (Vite/Webpack) instead of relying on generated temp “page component” files, and adjusts markdown asset/link handling accordingly.
Changes:
- Replace temp page component generation with a single “page chunk” model, rendering page SFC +
_pageDatavia bundler transforms/loaders. - Add
app.pagesMapplus a newonPageUpdatedhook to support dev updates (create/update/delete) and faster lookups during bundling. - Simplify markdown assets link resolution (remove
relativePathPrefix) and update unit/e2e coverage around markdown-as-vue-component + relative imports.
Reviewed changes
Copilot reviewed 54 out of 54 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/markdown/tests/plugins/assetsPlugin.spec.ts | Update expectations for new assets link resolution behavior. |
| packages/markdown/src/plugins/assetsPlugin/resolveLink.ts | Simplify link resolution logic and options surface. |
| packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts | Update assets plugin to use simplified resolveLink(). |
| packages/core/tests/pluginApi/createHookQueue.spec.ts | Add onPageUpdated hook to hook queue tests. |
| packages/core/tests/page/resolvePageComponentInfo.spec.ts | Remove tests for deleted page component temp-file info. |
| packages/core/tests/page/resolvePageChunkInfo.spec.ts | Update expectations for chunk file selection (source vs temp). |
| packages/core/tests/page/createPage.spec.ts | Update page creation expectations after removing component temp files. |
| packages/core/tests/app/resolveAppPages.spec.ts | Adapt tests to new { pages, pagesMap } return shape. |
| packages/core/src/types/pluginApi/hooks.ts | Add onPageUpdated lifecycle hook typing. |
| packages/core/src/types/page.ts | Remove componentFilePath* from Page type. |
| packages/core/src/types/app/app.ts | Add pagesMap to initialized app properties. |
| packages/core/src/pluginApi/createPluginApiHooks.ts | Register onPageUpdated hook queue. |
| packages/core/src/page/resolvePageComponentInfo.ts | Remove component temp-file info resolver. |
| packages/core/src/page/resolvePageChunkInfo.ts | Resolve chunk info to source file when available, else temp .vue. |
| packages/core/src/page/renderPageToVue.ts | New renderer: render page SFC blocks + inject _pageData + HMR glue. |
| packages/core/src/page/renderPageSfcBlocksToVue.ts | Remove old SFC-block renderer. |
| packages/core/src/page/index.ts | Export new renderPageToVue() and remove deleted exports. |
| packages/core/src/page/createPage.ts | Use resolvePageChunkInfo() only; drop component temp-file fields. |
| packages/core/src/app/resolveAppPages.ts | Return { pages, pagesMap } and build pagesMap during page creation. |
| packages/core/src/app/prepare/prepareSiteData.ts | Refactor site data HMR code to use optional chaining + const var name. |
| packages/core/src/app/prepare/prepareRoutes.ts | Refactor routes/redirects HMR code and exported var names. |
| packages/core/src/app/prepare/preparePageComponent.ts | Remove page component temp generation. |
| packages/core/src/app/prepare/preparePageChunk.ts | Only write temp chunk when page has no source file; otherwise bundler handles it. |
| packages/core/src/app/prepare/index.ts | Stop exporting removed preparePageComponent. |
| packages/core/src/app/appPrepare.ts | Prepare only chunks (no component temp files). |
| packages/core/src/app/appInit.ts | Store both pages and pagesMap from resolveAppPages(). |
| packages/client/src/types/routes.ts | Update PageChunk shape to { default, _pageData }. |
| packages/client/src/setupGlobalComputed.ts | Update page chunk usage + page data HMR to match new chunk shape. |
| packages/client/src/components/Content.ts | Load async route component via module.default; remove frontmatter watch. |
| packages/cli/src/commands/dev/handlePageUnlink.ts | Maintain pagesMap + trigger onPageUpdated('delete'). |
| packages/cli/src/commands/dev/handlePageChange.ts | Maintain pagesMap + trigger onPageUpdated('update'). |
| packages/cli/src/commands/dev/handlePageAdd.ts | Maintain pagesMap + trigger onPageUpdated('create'). |
| packages/bundler-webpack/tsdown.config.ts | Build and ship new vuepress-markdown-loader entry. |
| packages/bundler-webpack/src/loaders/vuepressMarkdownLoader.ts | New webpack loader: .md → renderPageToVue() with _pageData. |
| packages/bundler-webpack/src/loaders/vuepressMarkdownLoader.cts | CJS bridge export for the webpack markdown loader. |
| packages/bundler-webpack/src/config/handleModuleVue.ts | Add .md rule using vue-loader + vuepress markdown loader; unify SSR loader insertion. |
| packages/bundler-webpack/src/config/handleModule.ts | Thread app/isBuild through to module handlers. |
| packages/bundler-webpack/src/config/createBaseConfig.ts | Pass app into handleModule(). |
| packages/bundler-webpack/src/build/createServerConfig.ts | Remove redundant SSR-loader insertion (handled centrally now). |
| packages/bundler-webpack/src/build/createClientConfig.ts | Remove redundant SSR-loader insertion (handled centrally now). |
| packages/bundler-webpack/package.json | Expose #vuepress-markdown-loader import mapping. |
| packages/bundler-vite/src/resolveViteConfig.ts | Register new vuepressMarkdownPlugin. |
| packages/bundler-vite/src/plugins/vuepressVuePlugin.ts | Make Vite Vue plugin include .md files. |
| packages/bundler-vite/src/plugins/vuepressMarkdownPlugin.ts | New Vite plugin: .md → renderPageToVue() transform + hot update behavior. |
| packages/bundler-vite/src/plugins/index.ts | Export new markdown plugin. |
| eslint.config.ts | Allow _pageData as an internal/global-like identifier. |
| e2e/tests/markdown/vue-components.spec.ts | Update E2E assertions for split alias/relative component imports. |
| e2e/docs/markdown/vue-components.md | Demonstrate alias + relative imports from markdown <script setup>. |
| e2e/docs/README.md | Minor doc change (content adjustment). |
| e2e/docs/.vuepress/markdowns/dangling-markdown-file.md | Add markdown file to validate “import markdown as component” behavior. |
| e2e/docs/.vuepress/components/ComponentForMarkdownImportFoo.vue | New E2E component for alias import path. |
| e2e/docs/.vuepress/components/ComponentForMarkdownImportBar.vue | New E2E component for relative import path. |
| e2e/docs/.vuepress/components/ComponentForMarkdownImport.vue | Remove old E2E component (replaced by Foo/Bar). |
| .vscode/settings.json | Adjust workspace TS SDK setting key. |
Comments suppressed due to low confidence (1)
packages/markdown/src/plugins/assetsPlugin/resolveLink.ts:24
absolutePathPrependBasecurrently usespath.join(env.base, resolvedLink), but whenresolvedLinkstarts with/(e.g./absolute.png)join()will drop the base and return the absolute path unchanged. This will prevent/base/from being prepended as intended. Consider stripping the leading slash fromresolvedLink(or using URL-style concatenation) before joining so/absolute.pngbecomes/base/absolute.png.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Before submitting the PR, please make sure you do the following
close #123).What is the purpose of this pull request?
Description
Closes #1584
Changes:
TODOs
HMRRefactor dev watcher, update pages & pagesMapWatch page deps and invalidate the cache