Skip to content

Commit e36fa00

Browse files
committed
feat: webpack example
1 parent 011cb40 commit e36fa00

File tree

15 files changed

+3355
-29
lines changed

15 files changed

+3355
-29
lines changed

examples/webpack/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# uplugin-vue-router-webpack-example

examples/webpack/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="unplugin-vue-router/client" />

examples/webpack/package.json

Lines changed: 27 additions & 0 deletions
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+
}

examples/webpack/public/index.html

Lines changed: 16 additions & 0 deletions
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>

examples/webpack/shims-vue.d.ts

Lines changed: 6 additions & 0 deletions
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+
}

examples/webpack/src/App.vue

Lines changed: 18 additions & 0 deletions
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>

examples/webpack/src/main.ts

Lines changed: 13 additions & 0 deletions
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')

examples/webpack/src/pages/about.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<main>About</main>
3+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<main>Demo</main>
3+
</template>
Lines changed: 25 additions & 0 deletions
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>

0 commit comments

Comments
 (0)