Skip to content

Commit

Permalink
fix(webpack): handle loadInclude
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 16, 2023
1 parent b67d900 commit 9a43b63
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/index.ts
Expand Up @@ -92,9 +92,24 @@ export default createUnplugin<Options | undefined>((opt = {}, meta) => {
return ctx.definePageTransform(code, id)
},

// TODO: is it worth having a loadInclude?
// loadInclude is necessary for webpack
loadInclude(id) {
if (id === ROUTE_BLOCK_ID) return true
const resolvedId = getVirtualId(id)
return (
resolvedId === MODULE_ROUTES_PATH || resolvedId === MODULE_VUE_ROUTER
)
},

load(id) {
// remove the <route> block as it's parsed by the plugin
if (id === ROUTE_BLOCK_ID) {
return {
code: `export default {}`,
map: null,
}
}

// we need to use a virtual module so that vite resolves the vue-router/auto/routes
// dependency correctly
const resolvedId = getVirtualId(id)
Expand All @@ -108,14 +123,6 @@ export default createUnplugin<Options | undefined>((opt = {}, meta) => {
if (resolvedId === MODULE_VUE_ROUTER) {
return ctx.generateVueRouterProxy()
}

// remove the <route> block as it's parsed by the plugin
if (id === ROUTE_BLOCK_ID) {
return {
code: `export default {}`,
map: null,
}
}
},

// improves DX
Expand Down

0 comments on commit 9a43b63

Please sign in to comment.