Skip to content

Commit

Permalink
add support for vue components as part of library export
Browse files Browse the repository at this point in the history
  • Loading branch information
stackoverfloweth committed Jan 8, 2024
1 parent 775b871 commit bb2fbd1
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 3,948 deletions.
4,572 changes: 632 additions & 3,940 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"homepage": "https://github.com/kitbagjs/router#readme",
"scripts": {
"build": "tsc && vite build",
"build": "vue-tsc && vite build",
"test": "vitest",
"test:types": "vitest typecheck",
"lint": "eslint ./src",
Expand All @@ -29,14 +29,17 @@
},
"devDependencies": {
"@prefecthq/eslint-config": "^1.0.31",
"@vitejs/plugin-vue": "^5.0.2",
"eslint": "^8.54.0",
"happy-dom": "^12.10.3",
"typescript": "^5.0.2",
"vite": "^4.5.1",
"vite": "^5.0.11",
"vite-plugin-dts": "^3.6.3",
"vitest": "^0.34.6"
"vitest": "^0.34.6",
"vue": "^3.4.5",
"vue-tsc": "^1.8.27"
},
"peerDependencies": {
"vue": "^3.3.8"
"vue": "^3.4.5"
}
}
5 changes: 5 additions & 0 deletions src/components/RouterView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div class="router-view">
router-view
</div>
</template>
9 changes: 9 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import RouterView from '@/components/RouterView.vue'

Check failure on line 1 in src/components/index.ts

View workflow job for this annotation

GitHub Actions / Type Validation

Cannot find module '@/components/RouterView.vue' or its corresponding type declarations.

export { RouterView }

declare module '@vue/runtime-core' {
export interface GlobalComponents {
RouterView: typeof RouterView,
}
}
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './compositions'
export * from './components'
export * from './types'
export * from './utilities'
export * from './compositions'
export * from './utilities'
9 changes: 8 additions & 1 deletion src/utilities/createRouter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DeepReadonly, reactive, readonly } from 'vue'
import { DeepReadonly, reactive, readonly, App } from 'vue'
import { RouterView } from '@/components'
import { Resolved, Route, RouteMethods, Routes } from '@/types'
import { createRouteMethods, createRouterNavigation, resolveRoutes, routeMatch, getInitialUrl, resolveRoutesRegex } from '@/utilities'

Expand All @@ -19,6 +20,7 @@ export type Router<
back: () => void,
forward: () => void,
go: (delta: number) => void,
install: (app: App) => void,
}

export function createRouter<T extends Routes>(routes: T, options: RouterOptions = {}): Router<T> {
Expand All @@ -30,6 +32,10 @@ export function createRouter<T extends Routes>(routes: T, options: RouterOptions

const route: Resolved<Route> = reactive(getInitialRoute())

function install(app: App): void {
app.component('RouterView', RouterView)
}

function getInitialRoute(): Resolved<Route> {
const url = getInitialUrl(options.initialUrl)

Expand Down Expand Up @@ -69,6 +75,7 @@ export function createRouter<T extends Routes>(routes: T, options: RouterOptions
forward: navigation.forward,
back: navigation.back,
go: navigation.go,
install,
}

return router
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"exclude": ["node_modules", "dist", "public"]
}
2 changes: 2 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'path'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'

export default defineConfig({
Expand All @@ -25,6 +26,7 @@ export default defineConfig({
},
},
plugins: [
vue(),
dts({
rollupTypes: true
})
Expand Down

0 comments on commit bb2fbd1

Please sign in to comment.