Skip to content

Commit

Permalink
fix: correct module id
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 24, 2022
1 parent 4871a1e commit eb4ee83
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion @vue-router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This allows us to override imports from 'vue-router'
*/
import { routes } from '@vue-router/routes'
import { routes } from './routes'
import { createRouter as _createRouter } from 'vue-router'

export * from 'vue-router'
Expand Down
4 changes: 4 additions & 0 deletions @vue-router/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-nocheck
export { routes } from '@vue-router~routes'

// we use a flat id that can be resolved by vite
3 changes: 3 additions & 0 deletions src/core/moduleConstants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const MODULE_VUE_ROUTER = '@vue-router'
// the id is used internally and cannot contain slashes
export const MODULE_ROUTES_ID = `${MODULE_VUE_ROUTER}~routes`
// the path is used by the user and having slashes is just more natural
export const MODULE_ROUTES_PATH = `${MODULE_VUE_ROUTER}/routes`

export const VIRTUAL_PREFIX = 'virtual:'
Expand Down
12 changes: 3 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createUnplugin } from 'unplugin'
import { createRoutesContext } from './core/context'
import {
MODULE_ROUTES_PATH,
MODULE_ROUTES_ID,
MODULE_VUE_ROUTER,
VIRTUAL_PREFIX,
} from './core/moduleConstants'
Expand Down Expand Up @@ -30,7 +30,7 @@ export default createUnplugin<Options>((opt) => {
enforce: 'pre',

resolveId(id) {
if (id === MODULE_ROUTES_PATH) {
if (id === MODULE_ROUTES_ID) {
// virtual module
return asVirtualId(id)
}
Expand All @@ -47,19 +47,13 @@ export default createUnplugin<Options>((opt) => {

load(id) {
const resolvedId = getVirtualId(id)
if (resolvedId === MODULE_ROUTES_PATH) {
if (resolvedId === MODULE_ROUTES_ID) {
return ctx.generateRoutes()
}

// fallback
return null
},

vite: {
configureServer(server) {},
},

rollup: {},
}
})

Expand Down

0 comments on commit eb4ee83

Please sign in to comment.