@love-sqjm/magic 2026.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +93 -0
- package/app.js +51 -0
- package/doc/api/examples.md +563 -0
- package/doc/api/index.md +563 -0
- package/doc/architecture.md +322 -0
- package/doc/config-reference.md +646 -0
- package/doc/data-model.md +622 -0
- package/doc/development-guide.md +582 -0
- package/doc/magic-file/index.md +610 -0
- package/doc/user-guide/index.md +485 -0
- package/doc/workflow.md +548 -0
- package/index.js +157 -0
- package/magic.bat +2 -0
- package/magic.ps1 +5 -0
- package/package.json +44 -0
- package/script/build-project.js +16 -0
- package/script/config.js +23 -0
- package/script/create-project.js +73 -0
- package/script/global/printf.js +13 -0
- package/script/global/project-build-config.js +161 -0
- package/script/global/support-platform.js +5 -0
- package/script/module/compiler/global.js +43 -0
- package/script/module/compiler/id-generate.js +18 -0
- package/script/module/compiler/index-dom.js +78 -0
- package/script/module/compiler/macro-replace.js +22 -0
- package/script/module/compiler/macro.js +6 -0
- package/script/module/compiler/start.js +10 -0
- package/script/module/compiler/step/1.js +253 -0
- package/script/module/compiler/step/2.js +79 -0
- package/script/module/compiler/step/3.js +37 -0
- package/script/module/compiler/step/4.js +20 -0
- package/script/module/compiler/step/5.js +634 -0
- package/script/module/compiler/step/6.js +304 -0
- package/script/module/compiler/step/end.js +124 -0
- package/script/run-project.js +249 -0
- package/script/util/bun-fs.js +40 -0
- package/script/util/copy-dir.js +21 -0
- package/script/util/create-simple-dom-element.js +23 -0
- package/script/util/file-util.js +95 -0
- package/script/util/filtration-file.js +20 -0
- package/script/util/get-dir-all-file.js +28 -0
- package/script/util/get-first-object-key.js +9 -0
- package/script/util/is-empty-object.js +8 -0
- package/script/util/is-string-over-size.js +4 -0
- package/script/util/is.js +18 -0
- package/script/util/logging.js +142 -0
- package/script/util/task.js +16 -0
- package/script/util/traversal.js +28 -0
- package/template/platform-config/node-webkit +23 -0
- package/template/platform-config/web +1 -0
- package/template/project-base/app.xml +5 -0
- package/template/project-base/build.module.toml +37 -0
- package/template/project-base/build.toml +43 -0
- package/template/runtime/runtime.css +3 -0
- package/template/runtime/runtime.js +895 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
# build.toml 配置参考手册
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
`build.toml` 是 Magic 项目的构建配置文件,采用 TOML 格式。它定义了项目的基本信息、构建选项和平台配置。
|
|
6
|
+
|
|
7
|
+
## 完整配置示例
|
|
8
|
+
|
|
9
|
+
```toml
|
|
10
|
+
# 配置
|
|
11
|
+
[config]
|
|
12
|
+
name = "my-project"
|
|
13
|
+
src = "app"
|
|
14
|
+
main = "index"
|
|
15
|
+
|
|
16
|
+
[build]
|
|
17
|
+
out = "build"
|
|
18
|
+
model = "debug"
|
|
19
|
+
|
|
20
|
+
[build.platform]
|
|
21
|
+
target = "web"
|
|
22
|
+
|
|
23
|
+
[build.import]
|
|
24
|
+
module = []
|
|
25
|
+
|
|
26
|
+
[build.exclude]
|
|
27
|
+
file = []
|
|
28
|
+
dir = []
|
|
29
|
+
|
|
30
|
+
[build.optimize]
|
|
31
|
+
out-default-theme = true
|
|
32
|
+
|
|
33
|
+
[build.optimize.min-code]
|
|
34
|
+
js = false
|
|
35
|
+
css = false
|
|
36
|
+
html = false
|
|
37
|
+
|
|
38
|
+
[build.platform.config]
|
|
39
|
+
server = { port = 8088, host = "127.0.0.1" }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 配置项详解
|
|
43
|
+
|
|
44
|
+
### [config] - 项目配置
|
|
45
|
+
|
|
46
|
+
| 字段 | 类型 | 必需 | 默认值 | 说明 |
|
|
47
|
+
|------|------|------|--------|------|
|
|
48
|
+
| `name` | string | 是 | - | 项目名称 |
|
|
49
|
+
| `src` | string | 是 | - | 源码目录,相对于项目根目录 |
|
|
50
|
+
| `main` | string | 是 | - | 入口文件名(不含扩展名) |
|
|
51
|
+
|
|
52
|
+
**示例:**
|
|
53
|
+
```toml
|
|
54
|
+
[config]
|
|
55
|
+
name = "nice-game-creator"
|
|
56
|
+
src = "app"
|
|
57
|
+
main = "index"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### [build] - 构建配置
|
|
63
|
+
|
|
64
|
+
| 字段 | 类型 | 必需 | 默认值 | 说明 |
|
|
65
|
+
|------|------|------|--------|------|
|
|
66
|
+
| `out` | string | 否 | "build" | 构建输出目录 |
|
|
67
|
+
| `model` | string | 否 | "debug" | 构建模式: `debug` 或 `release` |
|
|
68
|
+
|
|
69
|
+
**debug vs release 模式:**
|
|
70
|
+
|
|
71
|
+
| 特性 | debug | release |
|
|
72
|
+
|------|-------|---------|
|
|
73
|
+
| 代码压缩 | 否 | 可配置 |
|
|
74
|
+
| CSS 压缩 | 否 | 可配置 |
|
|
75
|
+
| HTML 压缩 | 否 | 可配置 |
|
|
76
|
+
| 多个文件输出 | 是(按模块) | 可合并 |
|
|
77
|
+
| Source Map | 无 | 无 |
|
|
78
|
+
|
|
79
|
+
**示例:**
|
|
80
|
+
```toml
|
|
81
|
+
[build]
|
|
82
|
+
out = "dist"
|
|
83
|
+
model = "release"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### [build.platform] - 平台配置
|
|
89
|
+
|
|
90
|
+
| 字段 | 类型 | 必需 | 默认值 | 说明 |
|
|
91
|
+
|------|------|------|--------|------|
|
|
92
|
+
| `target` | string | 是 | - | 目标平台: `web`, `node-webkit`, `module` |
|
|
93
|
+
| `config` | object | 否 | {} | 平台特定配置 |
|
|
94
|
+
|
|
95
|
+
**支持的平台:**
|
|
96
|
+
|
|
97
|
+
| 平台 | 说明 |
|
|
98
|
+
|------|------|
|
|
99
|
+
| `web` | 浏览器环境 |
|
|
100
|
+
| `node-webkit` | Node-Webkit 桌面应用 |
|
|
101
|
+
| `module` | 可复用模块库 |
|
|
102
|
+
|
|
103
|
+
**示例:**
|
|
104
|
+
```toml
|
|
105
|
+
[build.platform]
|
|
106
|
+
target = "web"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### [build.platform.config] - 平台特定配置
|
|
112
|
+
|
|
113
|
+
#### Web 平台配置
|
|
114
|
+
|
|
115
|
+
```toml
|
|
116
|
+
[build.platform.config]
|
|
117
|
+
server = { port = 8088, host = "127.0.0.1" }
|
|
118
|
+
browser = true
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| 字段 | 类型 | 说明 |
|
|
122
|
+
|------|------|------|
|
|
123
|
+
| `server.port` | number | HTTP 服务器端口 |
|
|
124
|
+
| `server.host` | string | 服务器主机地址 |
|
|
125
|
+
| `browser` | boolean | 是否自动打开浏览器 |
|
|
126
|
+
|
|
127
|
+
**完整 Web 配置示例:**
|
|
128
|
+
```toml
|
|
129
|
+
[build.platform]
|
|
130
|
+
target = "web"
|
|
131
|
+
|
|
132
|
+
[build.platform.config]
|
|
133
|
+
browser = true
|
|
134
|
+
server = { port = 3000, host = "0.0.0.0" }
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Node-Webkit 平台配置
|
|
138
|
+
|
|
139
|
+
```toml
|
|
140
|
+
[build.platform]
|
|
141
|
+
target = "node-webkit"
|
|
142
|
+
|
|
143
|
+
[build.platform.config]
|
|
144
|
+
app = "/path/to/nw.exe"
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
| 字段 | 类型 | 说明 |
|
|
148
|
+
|------|------|------|
|
|
149
|
+
| `app` | string | NW.js 可执行文件路径 |
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### [build.import] - 模块导入配置
|
|
154
|
+
|
|
155
|
+
定义要导入的外部 Magic 模块。
|
|
156
|
+
|
|
157
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
158
|
+
|------|------|--------|------|
|
|
159
|
+
| `module` | array | [] | 模块路径列表 |
|
|
160
|
+
|
|
161
|
+
**示例:**
|
|
162
|
+
```toml
|
|
163
|
+
[build.import]
|
|
164
|
+
module = [
|
|
165
|
+
"./magic-ui",
|
|
166
|
+
"./common-components"
|
|
167
|
+
]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### [build.exclude] - 排除项配置
|
|
173
|
+
|
|
174
|
+
定义构建时排除的文件和目录。
|
|
175
|
+
|
|
176
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
177
|
+
|------|------|--------|------|
|
|
178
|
+
| `file` | array | [] | 排除的文件列表 |
|
|
179
|
+
| `dir` | array | [] | 排除的目录列表 |
|
|
180
|
+
|
|
181
|
+
**示例:**
|
|
182
|
+
```toml
|
|
183
|
+
[build.exclude]
|
|
184
|
+
file = ["app.xml", "private.txt"]
|
|
185
|
+
dir = ["test", "docs", ".git"]
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**默认排除项:**
|
|
189
|
+
- `app.xml` - 应用配置文件(自动排除)
|
|
190
|
+
- `magic/` - Magic 内部目录(自动排除)
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### [build.optimize] - 优化配置
|
|
195
|
+
|
|
196
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
197
|
+
|------|------|--------|------|
|
|
198
|
+
| `out-default-theme` | boolean | true | 是否输出默认主题 CSS 变量文件 |
|
|
199
|
+
|
|
200
|
+
#### out-default-theme
|
|
201
|
+
|
|
202
|
+
启用后,会生成 `default-theme-var.css` 文件,将组件中的 `default-theme` CSS 属性转换为 CSS 变量。
|
|
203
|
+
|
|
204
|
+
**示例:**
|
|
205
|
+
```toml
|
|
206
|
+
[build.optimize]
|
|
207
|
+
out-default-theme = false
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### [build.optimize.min-code] - 代码压缩配置
|
|
213
|
+
|
|
214
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
215
|
+
|------|------|--------|------|
|
|
216
|
+
| `js` | boolean | false | 是否压缩 JavaScript |
|
|
217
|
+
| `css` | boolean | false | 是否压缩 CSS |
|
|
218
|
+
| `html` | boolean | false | 是否压缩 HTML |
|
|
219
|
+
|
|
220
|
+
**注意:** 压缩只在 `model = "release"` 时生效。
|
|
221
|
+
|
|
222
|
+
**示例:**
|
|
223
|
+
```toml
|
|
224
|
+
[build.optimize]
|
|
225
|
+
out-default-theme = true
|
|
226
|
+
|
|
227
|
+
[build.optimize.min-code]
|
|
228
|
+
js = true
|
|
229
|
+
css = true
|
|
230
|
+
html = true
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## app.xml 配置参考
|
|
236
|
+
|
|
237
|
+
`app.xml` 是应用配置文件,位于源码目录中。
|
|
238
|
+
|
|
239
|
+
## 完整配置示例
|
|
240
|
+
|
|
241
|
+
```xml
|
|
242
|
+
<app lang="zh" icon="path/to/icon.png">
|
|
243
|
+
<title>My Application</title>
|
|
244
|
+
<init-script>
|
|
245
|
+
$INIT$
|
|
246
|
+
</init-script>
|
|
247
|
+
<import
|
|
248
|
+
dir="."
|
|
249
|
+
>
|
|
250
|
+
<group dir="magic-ui">
|
|
251
|
+
<css src="style.css"/>
|
|
252
|
+
<js src="runtime.js"/>
|
|
253
|
+
</group>
|
|
254
|
+
<js src="main.js"/>
|
|
255
|
+
</import>
|
|
256
|
+
</app>
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## 配置项详解
|
|
260
|
+
|
|
261
|
+
### app 根元素属性
|
|
262
|
+
|
|
263
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
264
|
+
|------|------|--------|------|
|
|
265
|
+
| `lang` | string | "zh" | 页面语言代码 |
|
|
266
|
+
| `icon` | string | - | 网站图标路径 |
|
|
267
|
+
|
|
268
|
+
**示例:**
|
|
269
|
+
```xml
|
|
270
|
+
<app lang="en" icon="./favicon.png">
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### title - 页面标题
|
|
276
|
+
|
|
277
|
+
```xml
|
|
278
|
+
<title>My Application</title>
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
设置浏览器标签页标题。
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
### init-script - 初始化脚本
|
|
286
|
+
|
|
287
|
+
```xml
|
|
288
|
+
<init-script>
|
|
289
|
+
$INIT$
|
|
290
|
+
</init-script>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**说明:**
|
|
294
|
+
- `$INIT$` 是占位符,会被替换为框架初始化代码
|
|
295
|
+
- 可以包裹在自定义代码中
|
|
296
|
+
|
|
297
|
+
**示例:**
|
|
298
|
+
```xml
|
|
299
|
+
<init-script>
|
|
300
|
+
console.log("Before init");
|
|
301
|
+
$INIT$
|
|
302
|
+
console.log("After init");
|
|
303
|
+
</init-script>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
### import - 资源导入
|
|
309
|
+
|
|
310
|
+
定义要加载的 CSS 和 JavaScript 资源。
|
|
311
|
+
|
|
312
|
+
#### 基本用法
|
|
313
|
+
|
|
314
|
+
```xml
|
|
315
|
+
<import>
|
|
316
|
+
<js src="main.js"/>
|
|
317
|
+
<css src="style.css"/>
|
|
318
|
+
</import>
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### dir 属性
|
|
322
|
+
|
|
323
|
+
设置资源的基础目录:
|
|
324
|
+
|
|
325
|
+
```xml
|
|
326
|
+
<import dir="lib">
|
|
327
|
+
<js src="jquery.js"/>
|
|
328
|
+
<css src="bootstrap.css"/>
|
|
329
|
+
</import>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### group 分组
|
|
333
|
+
|
|
334
|
+
使用 `<group>` 组织资源:
|
|
335
|
+
|
|
336
|
+
```xml
|
|
337
|
+
<import dir=".">
|
|
338
|
+
<group dir="css">
|
|
339
|
+
<css src="reset.css"/>
|
|
340
|
+
<css src="theme.css"/>
|
|
341
|
+
</group>
|
|
342
|
+
<group dir="js">
|
|
343
|
+
<js src="vendor.js"/>
|
|
344
|
+
<js src="app.js"/>
|
|
345
|
+
</group>
|
|
346
|
+
</import>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### load 属性
|
|
350
|
+
|
|
351
|
+
控制资源加载时机:
|
|
352
|
+
|
|
353
|
+
| 值 | 说明 |
|
|
354
|
+
|----|------|
|
|
355
|
+
| `begin` | 在头部加载(默认) |
|
|
356
|
+
| `end` | 在尾部加载 |
|
|
357
|
+
|
|
358
|
+
```xml
|
|
359
|
+
<js src="analytics.js" load="end"/>
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
### import 标签详解
|
|
365
|
+
|
|
366
|
+
#### js - JavaScript 资源
|
|
367
|
+
|
|
368
|
+
```xml
|
|
369
|
+
<js src="path/to/file.js" load="begin"/>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
| 属性 | 说明 |
|
|
373
|
+
|------|------|
|
|
374
|
+
| `src` | 文件路径 |
|
|
375
|
+
| `load` | 加载时机: `begin` 或 `end` |
|
|
376
|
+
|
|
377
|
+
#### css - CSS 资源
|
|
378
|
+
|
|
379
|
+
```xml
|
|
380
|
+
<css src="path/to/file.css" load="begin"/>
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
| 属性 | 说明 |
|
|
384
|
+
|------|------|
|
|
385
|
+
| `src` | 文件路径 |
|
|
386
|
+
| `load` | 加载时机: `begin` 或 `end` |
|
|
387
|
+
|
|
388
|
+
#### link - 外部链接
|
|
389
|
+
|
|
390
|
+
```xml
|
|
391
|
+
<link href="https://fonts.googleapis.com/css?family=Roboto"/>
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
### file - 内联文件内容
|
|
397
|
+
|
|
398
|
+
使用 `file` 标签可以内联文件内容:
|
|
399
|
+
|
|
400
|
+
```xml
|
|
401
|
+
<import>
|
|
402
|
+
<file path="./inline-template.html" load="begin"/>
|
|
403
|
+
</import>
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
### module-import - 模块导入
|
|
409
|
+
|
|
410
|
+
使用 `<module-import>` 标签可以导入一个包含 `.module-import` 配置文件的模块目录。
|
|
411
|
+
|
|
412
|
+
#### 基本用法
|
|
413
|
+
|
|
414
|
+
```xml
|
|
415
|
+
<import dir=".">
|
|
416
|
+
<module-import src="xxx-ui"/>
|
|
417
|
+
</import>
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
#### 工作原理
|
|
421
|
+
|
|
422
|
+
1. `module-import` 根据 `src` 属性在指定目录中查找 `.module-import` 文件
|
|
423
|
+
2. `.module-import` 文件定义了模块的 js、css、link、file 资源
|
|
424
|
+
3. 所有资源路径相对于模块目录
|
|
425
|
+
|
|
426
|
+
#### .module-import 文件格式
|
|
427
|
+
|
|
428
|
+
```text
|
|
429
|
+
js
|
|
430
|
+
-[load:front]critical.js
|
|
431
|
+
-runtime.js
|
|
432
|
+
css
|
|
433
|
+
-[load:end]mdi/materialdesignicons.min.css
|
|
434
|
+
-atom.css
|
|
435
|
+
-style.css
|
|
436
|
+
link
|
|
437
|
+
-https://fonts.googleapis.com/css?family=Roboto
|
|
438
|
+
file
|
|
439
|
+
-inline-template.html
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
格式说明:
|
|
443
|
+
- 以 `js`、`css`、`link`、`file` 开头表示分类
|
|
444
|
+
- 以 `-` 开头的行表示具体文件路径
|
|
445
|
+
- 支持 `[load:xxx]` 格式指定加载时机,可选值: `begin`、`end`、`front`
|
|
446
|
+
- `#` 开头或空行会被忽略
|
|
447
|
+
|
|
448
|
+
#### 完整示例
|
|
449
|
+
|
|
450
|
+
app.xml 配置:
|
|
451
|
+
```xml
|
|
452
|
+
<app lang="zh">
|
|
453
|
+
<title>Nice Game Creator</title>
|
|
454
|
+
<init-script>
|
|
455
|
+
$INIT$
|
|
456
|
+
</init-script>
|
|
457
|
+
<import dir=".">
|
|
458
|
+
<module-import src="xxx-ui"/>
|
|
459
|
+
<group dir="magic-ui">
|
|
460
|
+
<css src="style.css"/>
|
|
461
|
+
<js src="runtime.js"/>
|
|
462
|
+
</group>
|
|
463
|
+
<group dir="script">
|
|
464
|
+
<js src="platform.js"/>
|
|
465
|
+
</group>
|
|
466
|
+
</import>
|
|
467
|
+
</app>
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
模块目录结构:
|
|
471
|
+
```
|
|
472
|
+
xxx-ui/
|
|
473
|
+
├── .module-import # 模块配置文件
|
|
474
|
+
├── runtime.js # 资源文件
|
|
475
|
+
└── styles/
|
|
476
|
+
└── theme.css # 子目录资源
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
对应的 `.module-import 文件:
|
|
480
|
+
```
|
|
481
|
+
js
|
|
482
|
+
-runtime.js
|
|
483
|
+
css
|
|
484
|
+
-styles/theme.css
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
#### 资源加载顺序
|
|
488
|
+
|
|
489
|
+
HTML 中 head 区域的资源加载位置顺序:
|
|
490
|
+
|
|
491
|
+
```
|
|
492
|
+
[front] → [runtime.css] → [runtime.js] → [begin] → [/head]
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
body 区域的资源加载位置:
|
|
496
|
+
|
|
497
|
+
```
|
|
498
|
+
[begin] → [/body] → [end]
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
| 类型 | 默认 load | 说明 |
|
|
502
|
+
|------|-----------|------|
|
|
503
|
+
| js | `begin` | 在 head 区域加载 |
|
|
504
|
+
| css | `begin` | 在 head 区域加载 |
|
|
505
|
+
| link | `begin` | 在 head 区域加载 |
|
|
506
|
+
| file | `begin` | 内联内容,随 js/css 一起加载 |
|
|
507
|
+
|
|
508
|
+
**load 可选值:**
|
|
509
|
+
|
|
510
|
+
| 值 | 加载位置 | 说明 |
|
|
511
|
+
|----|----------|------|
|
|
512
|
+
| `front` | head 最开始 | 在 runtime.css 之前,用于关键 CSS/JS |
|
|
513
|
+
| `begin` | head 中间 | 在 runtime.js 之后 |
|
|
514
|
+
| `end` | body 末尾 | 在 `</body>` 之前 |
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
## 实战配置模板
|
|
519
|
+
|
|
520
|
+
### Web 开发配置
|
|
521
|
+
|
|
522
|
+
```toml
|
|
523
|
+
[config]
|
|
524
|
+
name = "my-web-app"
|
|
525
|
+
src = "app"
|
|
526
|
+
main = "index"
|
|
527
|
+
|
|
528
|
+
[build]
|
|
529
|
+
out = "build"
|
|
530
|
+
model = "debug"
|
|
531
|
+
|
|
532
|
+
[build.platform]
|
|
533
|
+
target = "web"
|
|
534
|
+
|
|
535
|
+
[build.platform.config]
|
|
536
|
+
browser = true
|
|
537
|
+
server = { port = 8088, host = "127.0.0.1" }
|
|
538
|
+
|
|
539
|
+
[build.exclude]
|
|
540
|
+
file = []
|
|
541
|
+
dir = []
|
|
542
|
+
|
|
543
|
+
[build.optimize]
|
|
544
|
+
out-default-theme = false
|
|
545
|
+
|
|
546
|
+
[build.optimize.min-code]
|
|
547
|
+
js = false
|
|
548
|
+
css = false
|
|
549
|
+
html = false
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### Web 生产配置
|
|
553
|
+
|
|
554
|
+
```toml
|
|
555
|
+
[config]
|
|
556
|
+
name = "my-web-app"
|
|
557
|
+
src = "app"
|
|
558
|
+
main = "index"
|
|
559
|
+
|
|
560
|
+
[build]
|
|
561
|
+
out = "dist"
|
|
562
|
+
model = "release"
|
|
563
|
+
|
|
564
|
+
[build.platform]
|
|
565
|
+
target = "web"
|
|
566
|
+
|
|
567
|
+
[build.platform.config]
|
|
568
|
+
server = { port = 80, host = "0.0.0.0" }
|
|
569
|
+
|
|
570
|
+
[build.import]
|
|
571
|
+
module = []
|
|
572
|
+
|
|
573
|
+
[build.exclude]
|
|
574
|
+
file = []
|
|
575
|
+
dir = []
|
|
576
|
+
|
|
577
|
+
[build.optimize]
|
|
578
|
+
out-default-theme = true
|
|
579
|
+
|
|
580
|
+
[build.optimize.min-code]
|
|
581
|
+
js = true
|
|
582
|
+
css = true
|
|
583
|
+
html = true
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### Node-Webkit 桌面应用配置
|
|
587
|
+
|
|
588
|
+
```toml
|
|
589
|
+
[config]
|
|
590
|
+
name = "my-desktop-app"
|
|
591
|
+
src = "app"
|
|
592
|
+
main = "index"
|
|
593
|
+
|
|
594
|
+
[build]
|
|
595
|
+
out = "build"
|
|
596
|
+
model = "release"
|
|
597
|
+
|
|
598
|
+
[build.platform]
|
|
599
|
+
target = "node-webkit"
|
|
600
|
+
|
|
601
|
+
[build.platform.config]
|
|
602
|
+
app = "C:/nwjs/nw.exe"
|
|
603
|
+
|
|
604
|
+
[build.exclude]
|
|
605
|
+
file = []
|
|
606
|
+
dir = []
|
|
607
|
+
|
|
608
|
+
[build.optimize]
|
|
609
|
+
out-default-theme = false
|
|
610
|
+
|
|
611
|
+
[build.optimize.min-code]
|
|
612
|
+
js = true
|
|
613
|
+
css = true
|
|
614
|
+
html = true
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
### 模块库配置
|
|
618
|
+
|
|
619
|
+
```toml
|
|
620
|
+
[config]
|
|
621
|
+
name = "my-magic-module"
|
|
622
|
+
src = "app"
|
|
623
|
+
version = "1.0.0"
|
|
624
|
+
description = "A reusable Magic module"
|
|
625
|
+
author = "Developer"
|
|
626
|
+
license = "MIT"
|
|
627
|
+
|
|
628
|
+
[build]
|
|
629
|
+
out = "dist"
|
|
630
|
+
model = "release"
|
|
631
|
+
|
|
632
|
+
[build.platform]
|
|
633
|
+
target = "module"
|
|
634
|
+
|
|
635
|
+
[build.exclude]
|
|
636
|
+
file = []
|
|
637
|
+
dir = []
|
|
638
|
+
|
|
639
|
+
[build.optimize]
|
|
640
|
+
out-default-theme = false
|
|
641
|
+
|
|
642
|
+
[build.optimize.min-code]
|
|
643
|
+
js = true
|
|
644
|
+
css = true
|
|
645
|
+
html = true
|
|
646
|
+
```
|