File tree 8 files changed +403
-514
lines changed
playground/src/pages/define-page
8 files changed +403
-514
lines changed Original file line number Diff line number Diff line change @@ -153,13 +153,17 @@ definePage({
153
153
154
154
函数
155
155
``` ts
156
+ import type { HelloWorld } from ' ./utils' ;
157
+
156
158
definePage (() => {
157
- const hello = ' hello' ;
158
- const world = ' world' ;
159
+ const words: HelloWorld = {
160
+ hello: ' hello' ,
161
+ world: ' world' ,
162
+ };
159
163
160
164
return {
161
165
style: {
162
- navigationBarTitleText: [hello , world ].join (' ' ),
166
+ navigationBarTitleText: [words . hello , words . world ].join (' ' ),
163
167
},
164
168
middlewares: [
165
169
' auth' ,
@@ -189,16 +193,16 @@ definePage(() => {
189
193
});
190
194
```
191
195
192
- 引入外部函数、变量
196
+ 引入外部函数、变量 ( *** 注意:仅支持引入纯 JavaScript 或仅 TypeScript 的类型声明。 *** )
193
197
``` ts
194
- import { randamText } from ' ./utils ' ;
198
+ import { parse as yamlParser } from ' yaml ' ;
195
199
196
200
definePage (() => {
197
- return {
198
- style: {
199
- navigationBarTitleText: randamText (),
200
- },
201
- } ;
201
+ const yml = `
202
+ style:
203
+ navigationBarTitleText: "yaml test"
204
+ ` ;
205
+ return yamlParser ( yml ) ;
202
206
});
203
207
```
204
208
Original file line number Diff line number Diff line change
1
+ import process from 'node:process' ;
1
2
import { defineBuildConfig } from 'unbuild' ;
2
3
4
+ const isDev = process . env . NODE_ENV === 'development' ;
5
+
3
6
export default defineBuildConfig ( {
4
7
entries : [ 'src/index' ] ,
5
8
declaration : true ,
@@ -8,9 +11,10 @@ export default defineBuildConfig({
8
11
emitCJS : true ,
9
12
inlineDependencies : true ,
10
13
esbuild : {
11
- minify : true ,
14
+ minify : ! isDev ,
12
15
} ,
13
16
} ,
14
17
externals : [ 'vite' ] ,
15
18
failOnWarn : false ,
19
+ sourcemap : isDev ,
16
20
} ) ;
Original file line number Diff line number Diff line change 46
46
"clean" : " rimraf dist" ,
47
47
"build" : " unbuild" ,
48
48
"stub" : " unbuild --stub" ,
49
- "debug" : " unbuild --sourcemap && cd playground && pnpm dev:h5" ,
49
+ "debug" : " cross-env NODE_ENV=development unbuild && cd playground && pnpm dev:h5" ,
50
50
"watch" : " tsup --watch" ,
51
51
"typecheck" : " tsc -p . --noEmit" ,
52
52
"lint" : " eslint ." ,
63
63
"debug" : " ^4.3.4" ,
64
64
"fast-glob" : " ^3.3.2" ,
65
65
"magic-string" : " ^0.30.8" ,
66
- "tsx " : " ^4.7.1 " ,
66
+ "typescript " : " ^5.4.5 " ,
67
67
"unconfig" : " ^0.3.11"
68
68
},
69
69
"devDependencies" : {
82
82
"@vue-macros/common" : " ^1.10.1" ,
83
83
"ast-walker-scope" : " ^0.6.1" ,
84
84
"bumpp" : " ^9.4.0" ,
85
+ "cross-env" : " ^7.0.3" ,
85
86
"debug" : " ^4.3.4" ,
86
87
"eslint" : " ^9.17.0" ,
87
88
"husky" : " ^9.0.11" ,
88
89
"lint-staged" : " ^15.2.2" ,
89
90
"magic-string" : " ^0.30.8" ,
90
91
"rimraf" : " ^5.0.5" ,
91
- "typescript" : " ^5.4.2" ,
92
92
"unbuild" : " ^3.3.1" ,
93
93
"unconfig" : " ^0.3.11" ,
94
94
"unplugin" : " ^1.10.0" ,
Original file line number Diff line number Diff line change 1
1
<script lang="ts" setup>
2
- definePage (() => {
3
- const hello = ' hello' ;
2
+ import type { HelloWorld } from ' ./utils' ;
4
3
5
- const world = ' world' ;
4
+ definePage (() => {
5
+ const words: HelloWorld = {
6
+ hello: ' hello' ,
7
+ world: ' world' ,
8
+ };
6
9
7
10
return {
8
11
style: {
9
- navigationBarTitleText: [hello , world ].join (' ' ),
12
+ navigationBarTitleText: [words . hello , words . world ].join (' ' ),
10
13
},
11
14
middlewares: [
12
15
' auth' ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- export function randamText ( ) {
2
- return Math . random ( ) . toString ( 36 ) . slice ( - 8 ) ;
1
+ export interface HelloWorld {
2
+ hello : string ;
3
+ world : string ;
3
4
}
You can’t perform that action at this time.
0 commit comments