Skip to content

Commit 9668fbb

Browse files
zhangmo8jiahengz
authored and
jiahengz
committed
# This is a combination of 7 commits.
# This is the 1st commit message: chore: resolve conflicts # This is the commit message posva#2: fix: fix the vue-loader error # This is the commit message posva#3: fix: setup return route # This is the commit message posva#4: fix: lint fix # This is the commit message posva#5: Update examples/webpack/shims-vue.d.ts Co-authored-by: Eduardo San Martin Morote <[email protected]> # This is the commit message posva#6: chore: update webpack deps & lock file # This is the commit message posva#7: chore: update webpack deps & lock file
1 parent af290b9 commit 9668fbb

15 files changed

+3325
-44
lines changed

Diff for: examples/webpack/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# uplugin-vue-router-webpack-example

Diff for: examples/webpack/env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="unplugin-vue-router/client" />

Diff for: examples/webpack/package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "webpack",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vue-cli-service serve",
7+
"build": "vue-cli-service build",
8+
"preview": "npm run build && serve -s dist"
9+
},
10+
"dependencies": {
11+
"vue": "^3.3.4",
12+
"vue-loader": "^17.4.2",
13+
"vue-router": "^4.2.2"
14+
},
15+
"devDependencies": {
16+
"@vue/cli-plugin-router": "^5.0.8",
17+
"@vue/cli-plugin-typescript": "^5.0.8",
18+
"typescript": "^5.5.4",
19+
"unplugin-vue-router": "workspace:*"
20+
},
21+
"browserslist": [
22+
"> 1%",
23+
"last 2 versions",
24+
"not dead",
25+
"not ie 11"
26+
]
27+
}

Diff for: examples/webpack/public/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title><%= htmlWebpackPlugin.options.title %></title>
8+
</head>
9+
<body>
10+
<noscript>
11+
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
12+
</noscript>
13+
<div id="app"></div>
14+
<!-- built files will be auto injected -->
15+
</body>
16+
</html>

Diff for: examples/webpack/shims-vue.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable */
2+
declare module '*.vue' {
3+
import type { DefineComponent } from 'vue'
4+
const component: DefineComponent<{}, {}, any>
5+
export default component
6+
}

Diff for: examples/webpack/src/App.vue

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script lang="ts" setup>
2+
import { useRoute } from 'vue-router'
3+
4+
const route = useRoute()
5+
</script>
6+
7+
<template>
8+
<header>
9+
<div class="wrapper">
10+
<mark>current page name is: {{ route.name }}</mark>
11+
<nav>
12+
<RouterLink to="/">Home</RouterLink>
13+
<RouterLink to="/demo">Demo</RouterLink>
14+
</nav>
15+
</div>
16+
</header>
17+
<router-view></router-view>
18+
</template>

Diff for: examples/webpack/src/main.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createApp } from 'vue'
2+
import App from './App.vue'
3+
import { createWebHistory, createRouter } from 'vue-router'
4+
import { routes } from 'vue-router/auto-routes'
5+
6+
const router = createRouter({
7+
history: createWebHistory(),
8+
routes,
9+
})
10+
11+
const app = createApp(App)
12+
app.use(router)
13+
app.mount('#app')

Diff for: examples/webpack/src/pages/about.vue

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<main>About</main>
3+
</template>

Diff for: examples/webpack/src/pages/demo/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<main>Demo</main>
3+
</template>

Diff for: examples/webpack/src/pages/detail/[id].vue

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts">
2+
import { definePage } from 'unplugin-vue-router/runtime'
3+
import { useRoute } from 'vue-router/auto'
4+
5+
export default {
6+
setup() {
7+
const route = useRoute()
8+
9+
definePage({
10+
meta: {
11+
iu: true,
12+
},
13+
})
14+
15+
console.log(route.meta)
16+
return {
17+
route,
18+
}
19+
},
20+
}
21+
</script>
22+
23+
<template>
24+
<main>Detail {{ route.params.id }}</main>
25+
</template>

Diff for: examples/webpack/src/pages/index.vue

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts" setup>
2+
import { ref } from 'vue'
3+
4+
const msg = ref('hello world')
5+
</script>
6+
7+
<template>
8+
<main>Home {{ msg }}</main>
9+
</template>

Diff for: examples/webpack/tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "@vue/tsconfig/tsconfig.dom.json",
3+
"include": [
4+
"./env.d.ts",
5+
"shims-vue.d.ts",
6+
"src/**/*",
7+
"src/**/*.vue",
8+
"shims-vue.d.ts",
9+
"./typed-router.d.ts"
10+
],
11+
"moduleFileExtensions": ["ts", "js", "vue", "json"],
12+
"compilerOptions": {
13+
"moduleResolution": "Bundler",
14+
"baseUrl": "../../"
15+
}
16+
}

Diff for: examples/webpack/typed-router.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable */
2+
/* prettier-ignore */
3+
// @ts-nocheck
4+
// Generated by unplugin-vue-router. ‼️ DO NOT MODIFY THIS FILE ‼️
5+
// It's recommended to commit this file.
6+
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.
7+
8+
declare module 'vue-router/auto-routes' {
9+
import type {
10+
RouteRecordInfo,
11+
ParamValue,
12+
ParamValueOneOrMore,
13+
ParamValueZeroOrMore,
14+
ParamValueZeroOrOne,
15+
} from 'vue-router'
16+
17+
/**
18+
* Route name map generated by unplugin-vue-router
19+
*/
20+
export interface RouteNamedMap {
21+
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
22+
'/about': RouteRecordInfo<'/about', '/about', Record<never, never>, Record<never, never>>,
23+
'/demo/': RouteRecordInfo<'/demo/', '/demo', Record<never, never>, Record<never, never>>,
24+
'/detail/[id]': RouteRecordInfo<'/detail/[id]', '/detail/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
25+
}
26+
}

Diff for: examples/webpack/vue.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { defineConfig } from '@vue/cli-service'
2+
import routerPlugin from 'unplugin-vue-router/webpack'
3+
4+
export default defineConfig({
5+
lintOnSave: false,
6+
configureWebpack: {
7+
plugins: [
8+
routerPlugin({
9+
routesFolder: './src/pages',
10+
}),
11+
],
12+
devServer: {
13+
allowedHosts: 'all',
14+
},
15+
output: {
16+
libraryTarget: 'module',
17+
},
18+
experiments: {
19+
outputModule: true,
20+
},
21+
},
22+
})

0 commit comments

Comments
 (0)