Skip to content

Commit 3df6a8a

Browse files
committed
fix: update examples
1 parent 7449b56 commit 3df6a8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+5106
-11846
lines changed

examples/backend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ npm run preview # start preview
3333
### i18n resource pre-compilation
3434

3535
```sh
36-
npm run generate # i18n resources pre-compilation
36+
npm run generate # i18n resources pre-compilation
3737
npm run preview # start preview
3838
```
3939

examples/backend/db/message.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import en from './en.json'
1+
import en from './en.json' with { type: 'json' }
22

33
export type ResourceSchema = typeof en

examples/backend/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
"name": "backend",
33
"version": "0.0.0",
44
"private": true,
5+
"type": "module",
56
"scripts": {
67
"dev": "vite",
7-
"generate": "npx --no-install jiti ./scripts/generate.ts",
8+
"generate": "pnpx tsx ./scripts/generate.ts",
89
"build": "vite build",
910
"check": "vue-tsc --noEmit",
10-
"serve": "npx --no-install jiti ./scripts/server.ts",
11+
"serve": "pnpx tsx ./scripts/server.ts",
1112
"preview": "vite preview"
1213
},
1314
"dependencies": {
1415
"vue": "^3.3.4",
1516
"vue-i18n": "11.1.12"
1617
},
1718
"devDependencies": {
18-
"@vitejs/plugin-vue": "^4.2.3",
19-
"vite": "^4.5.2",
19+
"@vitejs/plugin-vue": "^6.0.1",
20+
"vite": "^7.1.7",
2021
"typescript": "^5.0.2",
21-
"vue-tsc": "^1.8.5",
22+
"vue-tsc": "^3.0.7",
2223
"h3": "^1.8.0",
2324
"@types/express": "^4.17.13",
2425
"@types/body-parser": "^1.19.2",
2526
"express": "^4.19.2",
2627
"body-parser": "^1.20.3",
27-
"jiti": "^1.19.3",
2828
"ofetch": "^1.1.1",
2929
"@intlify/unplugin-vue-i18n": "^11.0.1",
30-
"@intlify/bundle-utils": "^10.0.1"
30+
"@intlify/bundle-utils": "^11.0.1"
3131
}
3232
}

examples/backend/scripts/generate.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Locale } from 'vue-i18n'
99
import type { ResourceSchema } from '../db/message'
1010

1111
async function compile(locale: string, message: ResourceSchema) {
12-
const filename = path.join(__dirname, `../public/${locale}.js`)
12+
const filename = path.join(import.meta.dirname, `../public/${locale}.js`)
1313
const ret = generateJSON(JSON.stringify(message), {
1414
type: 'plain',
1515
filename,
@@ -24,7 +24,7 @@ async function compile(locale: string, message: ResourceSchema) {
2424
return { ...ret, filename }
2525
}
2626

27-
;(async (locales: readonly Locale[]) => {
27+
async function main(locales: readonly Locale[]) {
2828
// start vite server
2929
const vite = await createServer({ root: process.cwd() })
3030
await vite.listen(3000)
@@ -48,4 +48,6 @@ async function compile(locale: string, message: ResourceSchema) {
4848
})
4949

5050
process.exit(0)
51-
})(locales)
51+
}
52+
53+
await main(locales as readonly Locale[])

examples/backend/scripts/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ router.get(
77
'/api/resources/:locale',
88
eventHandler(async event => {
99
const locale = event.context.params?.locale ?? 'en'
10-
const data = await import(`../db/${locale}.json`)
10+
const { default: data } = await import(`../db/${locale}.json`, { with: { type: 'json' } })
1111
setHeaders(event, {
1212
'Access-Control-Allow-Origin': '*'
1313
})

examples/backend/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createApp } from 'vue'
22
import { createI18n } from 'vue-i18n'
33
import App from './App.vue'
4-
import { load } from './locales'
54
import { locales } from './constants'
5+
import { load } from './locales'
66

77
import type { ResourceSchema } from '../db/message'
88
import type { Locales } from './constants'

examples/backend/tsconfig.app.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "@vue/tsconfig/tsconfig.dom.json",
3+
"compilerOptions": {
4+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
5+
6+
/* Linting */
7+
"strict": true,
8+
"noUnusedLocals": true,
9+
"noUnusedParameters": true,
10+
"erasableSyntaxOnly": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"noUncheckedSideEffectImports": true
13+
},
14+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
15+
}

examples/backend/tsconfig.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
{
2-
"compilerOptions": {
3-
"target": "esnext",
4-
"useDefineForClassFields": true,
5-
"module": "esnext",
6-
"moduleResolution": "node",
7-
"strict": true,
8-
"jsx": "preserve",
9-
"sourceMap": true,
10-
"resolveJsonModule": true,
11-
"esModuleInterop": true,
12-
"lib": ["esnext", "dom"]
13-
},
14-
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
2+
"files": [],
3+
"references": [
4+
{ "path": "./tsconfig.app.json" },
5+
{ "path": "./tsconfig.node.json" }
6+
]
157
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4+
"target": "ES2023",
5+
"lib": ["ES2023"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
8+
9+
/* Bundler mode */
10+
"moduleResolution": "bundler",
11+
"allowImportingTsExtensions": true,
12+
"verbatimModuleSyntax": true,
13+
"moduleDetection": "force",
14+
"noEmit": true,
15+
16+
/* Linting */
17+
"strict": true,
18+
"noUnusedLocals": true,
19+
"noUnusedParameters": true,
20+
"erasableSyntaxOnly": true,
21+
"noFallthroughCasesInSwitch": true,
22+
"noUncheckedSideEffectImports": true
23+
},
24+
"include": ["vite.config.ts"]
25+
}

examples/backend/vite.config.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { defineConfig } from 'vite'
2-
import vue from '@vitejs/plugin-vue'
31
import vueI18n from '@intlify/unplugin-vue-i18n/vite'
2+
import vue from '@vitejs/plugin-vue'
43
import bodyParser from 'body-parser'
4+
import { defineConfig } from 'vite'
55

66
/**
77
* These imports simulate the loading of resources from the database
88
*/
99
import en from './db/en.json' // english resources
1010
import ja from './db/ja.json' // japanese resources
1111

12-
import type { Plugin } from 'vite'
1312
import type { ServerResponse } from 'http'
13+
import type { Plugin } from 'vite'
1414
import type { ResourceSchema } from './db/message'
1515

1616
function serialize(res: ServerResponse, locales: ResourceSchema): void {
@@ -43,11 +43,5 @@ export default defineConfig({
4343
build: {
4444
target: 'esnext'
4545
},
46-
plugins: [
47-
backend(),
48-
vue(),
49-
vueI18n({
50-
jitCompilation: true
51-
})
52-
]
46+
plugins: [backend(), vue(), vueI18n()]
5347
})

0 commit comments

Comments
 (0)