unplugin-vue-router
Advanced tools
Comparing version 0.0.4 to 0.0.5
import * as unplugin from 'unplugin'; | ||
import { Options } from './options.js'; | ||
import { T as TreeLeaf, O as Options } from './options-43eb89e9.js'; | ||
import { RouteParamsRaw, RouteParams, RouteMeta, RouteLocationNormalized, RouteRecordName, RouteLocationNormalizedLoaded, RouteQueryAndHash, RouteLocationOptions, RouteLocation, NavigationGuardNext, NavigationFailure, Router, RouterLinkProps as RouterLinkProps$1 } from 'vue-router'; | ||
import { Ref, AllowedComponentProps, ComponentCustomProps, VNodeProps, VNode } from 'vue'; | ||
declare type LiteralStringUnion<LiteralType, BaseType extends string = string> = LiteralType | (BaseType & Record<never, never>); | ||
/** | ||
* Creates a name based of the node path segments. | ||
* | ||
* @param node - the node to get the path from | ||
* @param parent - the parent node | ||
* @returns a route name | ||
*/ | ||
declare function getPascalCaseRouteName(node: TreeLeaf): string; | ||
/** | ||
* Joins the path segments of a node into a name that corresponds to the filepath represented by the node. | ||
* | ||
* @param node - the node to get the path from | ||
* @returns a route name | ||
*/ | ||
declare function getFileBasedRouteName(node: TreeLeaf): string; | ||
interface RouteRecordInfo<Name extends string = string, Path extends string = string, ParamsRaw extends RouteParamsRaw = RouteParamsRaw, Params extends RouteParams = RouteParams, Meta extends RouteMeta = RouteMeta> { | ||
@@ -15,4 +32,2 @@ name: Name; | ||
declare type LiteralStringUnion<LiteralType, BaseType extends string = string> = LiteralType | (BaseType & Record<never, never>); | ||
interface RouteLocationNormalizedTyped<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalized { | ||
@@ -117,2 +132,2 @@ name: Extract<Name, RouteRecordName>; | ||
export { NavigationGuard, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteRecordInfo, RouterLinkTyped, _ParamValue, _ParamValueOneOrMore, _ParamValueZeroOrMore, _ParamValueZeroOrOne, _RouteMapGeneric, _RouterTyped, _default as default }; | ||
export { NavigationGuard, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteRecordInfo, RouterLinkTyped, _ParamValue, _ParamValueOneOrMore, _ParamValueZeroOrMore, _ParamValueZeroOrOne, _RouteMapGeneric, _RouterTyped, _default as default, getFileBasedRouteName, getPascalCaseRouteName }; |
@@ -1,24 +0,1 @@ | ||
interface Options { | ||
extensions?: string[]; | ||
/** | ||
* Folder containing the components that should be used for routes. | ||
* | ||
* @default "src/routes" | ||
*/ | ||
routesFolder?: string; | ||
importMode?: 'sync' | 'async' | ((path: string, resolvedOptions: Options) => 'sync' | 'async'); | ||
exclude?: string[]; | ||
root?: string; | ||
/** | ||
* Should generate d.ts files. Defaults to `true` if `typescript` is installed. | ||
*/ | ||
dts?: boolean; | ||
/** | ||
* Allows inspection by vite-plugin-inspect by not adding the leading `\0` to the id of virtual modules. | ||
* @internal | ||
*/ | ||
_inspect?: boolean; | ||
} | ||
declare const DEFAULT_OPTIONS: Required<Options>; | ||
export { DEFAULT_OPTIONS, Options }; | ||
export { D as DEFAULT_OPTIONS, O as Options } from './options-43eb89e9.js'; |
@@ -26,2 +26,13 @@ var __defProp = Object.defineProperty; | ||
var import_local_pkg = require("local-pkg"); | ||
// src/core/utils.ts | ||
var import_scule = require("scule"); | ||
var isArray = Array.isArray; | ||
function getFileBasedRouteName(node) { | ||
if (!node.parent) | ||
return ""; | ||
return getFileBasedRouteName(node.parent) + "/" + node.value.rawSegment; | ||
} | ||
// src/options.ts | ||
var DEFAULT_OPTIONS = { | ||
@@ -31,2 +42,3 @@ extensions: [".vue", ".js", ".jsx", ".ts", ".tsx"], | ||
routesFolder: "src/routes", | ||
getRouteName: getFileBasedRouteName, | ||
importMode: "async", | ||
@@ -33,0 +45,0 @@ root: process.cwd(), |
import * as unplugin from 'unplugin'; | ||
import { Options } from './options.js'; | ||
import { O as Options } from './options-43eb89e9.js'; | ||
@@ -4,0 +4,0 @@ declare const _default: (options?: Options | undefined) => unplugin.RollupPlugin; |
import * as unplugin from 'unplugin'; | ||
import { Options } from './options.js'; | ||
import { O as Options } from './options-43eb89e9.js'; | ||
@@ -4,0 +4,0 @@ declare const _default: (options?: Options | undefined) => unplugin.VitePlugin; |
import * as webpack from 'webpack'; | ||
import { Options } from './options.js'; | ||
import { O as Options } from './options-43eb89e9.js'; | ||
@@ -4,0 +4,0 @@ declare const _default: (options?: Options | undefined) => webpack.WebpackPluginInstance; |
{ | ||
"name": "unplugin-vue-router", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"packageManager": "pnpm@7.1.7", | ||
@@ -42,6 +42,2 @@ "description": "Register global imports on demand for Vite and Webpack", | ||
}, | ||
"./nuxt": { | ||
"require": "./dist/nuxt.js", | ||
"import": "./dist/nuxt.mjs" | ||
}, | ||
"./types": { | ||
@@ -60,6 +56,6 @@ "require": "./dist/types.js", | ||
"local-pkg": "^0.4.1", | ||
"scule": "^0.2.1", | ||
"unplugin": "^0.7.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.34", | ||
"bumpp": "^8.1.0", | ||
@@ -66,0 +62,0 @@ "esno": "^0.16.3", |
@@ -9,3 +9,3 @@ # unplugin-vue-router | ||
⚠️ This package is still experimental. If you found any issue, flow, or have ideas to improve it, please, [open an issue](https://github.com/posva/unplugin-vue-router/issues/new/choose). | ||
⚠️ This package is still experimental. If you found any issue, design flaw, or have ideas to improve it, please, open an [issue](https://github.com/posva/unplugin-vue-router/issues/new/choose) or a [Discussion](https://github.com/posva/unplugin-vue-router/discussions). | ||
@@ -74,23 +74,2 @@ ## Install | ||
<details> | ||
<summary>Nuxt</summary><br> | ||
```ts | ||
// nuxt.config.js | ||
export default { | ||
buildModules: [ | ||
[ | ||
'unplugin-vue-router/nuxt', | ||
{ | ||
/* options */ | ||
}, | ||
], | ||
], | ||
} | ||
``` | ||
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite) | ||
<br></details> | ||
<details> | ||
<summary>Vue CLI</summary><br> | ||
@@ -113,5 +92,48 @@ | ||
Then you can replace your imports from `vue-router` to `@vue-router`: | ||
```diff | ||
-import { createRouter, createWebHistory } from 'vue-router' | ||
+import { createRouter, createWebHistory } from '@vue-router' | ||
createRouter({ | ||
history: createWebHistory(), | ||
// You don't need to pass the routes anymore, | ||
// the plugin writes it for you 🤖 | ||
}) | ||
``` | ||
Make sure to also check [the TypeScript section](#typescript) below if you are using TypeScript. | ||
## Configuration | ||
Have a glimpse of all the existing configuration options with their corresponding **default values**: | ||
```ts | ||
VueRouter({ | ||
// Folder(s) to scan for vue components and generate routes. Can be a string or an array of strings. | ||
routesFolder: 'src/routes' | ||
// Path for the generated types. Defaults to `./typed-router.d.ts` if typescript | ||
// is installed. Can be disabled by passing `false`. | ||
dts: './typed-router.d.ts', | ||
}) | ||
``` | ||
## TypeScript | ||
This plugin generates a `d.ts` file with all the typing overrides. Make sure to include it in your `tsconfig.json`'s `include` or `files` property: | ||
```js | ||
{ | ||
// ... | ||
"include": [/* ... */ "typed-router.d.ts"] | ||
// ... | ||
} | ||
``` | ||
Make sure to import from `@vue-router` to get access to the typed APIs instead of `vue-router`. You can commit the `typed-router.d.ts` file to your repository to make your life easier. | ||
## Rationale | ||
This project idea came from trying to [type the router directly using Typescript](https://github.com/vuejs/router/pull/1397/commits/c577998f3edaa6a1eb9474c27ab6c58f6e2d7c8a), finding it out it's not fast enough to be pleasant to use and recurring to build-based tools, taking some Inspiration from other projects like: | ||
This project idea came from trying [to type the router directly using Typescript](https://github.com/vuejs/router/pull/1397/commits/c577998f3edaa6a1eb9474c27ab6c58f6e2d7c8a), finding out it's not fast enough to be pleasant to use and, ending up using build-based tools, taking some inspiration from other projects like: | ||
@@ -118,0 +140,0 @@ - [Nuxt](https://nuxtjs.org/) - The Vue.js Framework |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15
144
20
1047837
4
28
29175
+ Addedscule@^0.2.1
+ Addedscule@0.2.1(transitive)