Skip to content

Commit

Permalink
feat: support TS in definePage
Browse files Browse the repository at this point in the history
Close #57
Close #238
  • Loading branch information
posva committed Jun 18, 2024
1 parent d851b61 commit 4fbff23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion playground/src/pages/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ definePage({
meta: {
// hello: 'there',
mySymbol: Symbol(),
// test: (to: RouteLocationNormalized) => console.log(to.name === '/[name]' ? to.params.name : 'nope'),
test: (to: RouteLocationNormalized) =>
console.log(to.name === '/[name]' ? to.params.name : 'nope'),
},
})
Expand Down
6 changes: 5 additions & 1 deletion src/codegen/generateRouteRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ ${startIndent}}`
for (const [name, filePath] of node.value.components) {
const pageDataImport = `_definePage_${name}_${importsMap.size}`
definePageDataList.push(pageDataImport)
importsMap.addDefault(`${filePath}?definePage&vue`, pageDataImport)
importsMap.addDefault(
// TODO: apply the language used in the sfc
`${filePath}?definePage&vue&lang.tsx`,
pageDataImport
)
}

if (definePageDataList.length) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default createUnplugin<Options | undefined>((opt = {}, _meta) => {
pageFilePattern.map((pattern) => join(routeOption.src, pattern))
),
// importing the definePage block
/definePage\&vue$/,
/\?.*\bdefinePage\&vue\b/,
],
options.exclude
)
Expand Down Expand Up @@ -97,6 +97,7 @@ export default createUnplugin<Options | undefined>((opt = {}, _meta) => {

transform(code, id) {
// console.log('👋 ', id)
// remove the `definePage()` from the file or isolate it
return ctx.definePageTransform(code, id)
},

Expand Down

0 comments on commit 4fbff23

Please sign in to comment.