@dtwo/schema 3.0.0-rc.14 → 3.1.0-0
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 +1 -1
- package/README.md +6 -2
- package/dist/index.d.ts +1193 -1019
- package/dist/index.mjs +945 -5
- package/package.json +23 -22
- package/schema/config.d.ts +1168 -1012
- package/schema/config.defaults.json +6 -4
- package/schema/config.md +22 -13
- package/schema/config.schema.json +117 -64
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,15 @@ import createResolver from 'postcss-import-resolver';
|
|
|
7
7
|
import { withoutLeadingSlash } from 'ufo';
|
|
8
8
|
|
|
9
9
|
const adhoc = defineUntypedSchema({
|
|
10
|
+
/**
|
|
11
|
+
* Configure Dtwo component auto-registration.
|
|
12
|
+
*
|
|
13
|
+
* Any components in the directories configured here can be used throughout your
|
|
14
|
+
* pages, layouts (and other components) without needing to explicitly import them.
|
|
15
|
+
*
|
|
16
|
+
* @see https://dtwojs.web.app/docs/guide/directory-structure/components
|
|
17
|
+
* @type {boolean | typeof import('../src/types/components').ComponentsOptions | typeof import('../src/types/components').ComponentsOptions['dirs']}
|
|
18
|
+
*/
|
|
10
19
|
components: {
|
|
11
20
|
$resolve: (val) => {
|
|
12
21
|
if (Array.isArray(val)) {
|
|
@@ -18,28 +27,119 @@ const adhoc = defineUntypedSchema({
|
|
|
18
27
|
return val;
|
|
19
28
|
}
|
|
20
29
|
},
|
|
30
|
+
/**
|
|
31
|
+
* Configure how Dtwo auto-imports composables into your application.
|
|
32
|
+
*
|
|
33
|
+
* @see [Dtwo 3 documentation](https://dtwojs.web.app/docs/guide/directory-structure/composables)
|
|
34
|
+
* @type {typeof import('../src/types/imports').ImportsOptions}
|
|
35
|
+
*/
|
|
21
36
|
imports: {
|
|
22
37
|
global: false,
|
|
38
|
+
/**
|
|
39
|
+
* An array of custom directories that will be auto-imported.
|
|
40
|
+
* Note that this option will not override the default directories (~/composables, ~/utils).
|
|
41
|
+
* @example
|
|
42
|
+
* ```js
|
|
43
|
+
* imports: {
|
|
44
|
+
* // Auto-import crabs stores defined in `~/stores`
|
|
45
|
+
* dirs: ['stores']
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
23
49
|
dirs: []
|
|
24
50
|
},
|
|
51
|
+
/**
|
|
52
|
+
* Whether to use the kdu-router integration in Dtwo 3. If you do not provide a value it will be
|
|
53
|
+
* enabled if you have a `pages/` directory in your source folder.
|
|
54
|
+
*
|
|
55
|
+
* @type {boolean}
|
|
56
|
+
*/
|
|
25
57
|
pages: void 0,
|
|
58
|
+
/**
|
|
59
|
+
* Manually disable dtwo telemetry.
|
|
60
|
+
*
|
|
61
|
+
* @type {boolean}
|
|
62
|
+
*/
|
|
26
63
|
telemetry: void 0
|
|
27
64
|
});
|
|
28
65
|
|
|
29
66
|
const app = defineUntypedSchema({
|
|
67
|
+
/**
|
|
68
|
+
* Kdu.js config
|
|
69
|
+
*/
|
|
30
70
|
kdu: {
|
|
71
|
+
/**
|
|
72
|
+
* Options for the Kdu compiler that will be passed at build time.
|
|
73
|
+
* @see [documentation](https://kdu-js.web.app/api/application.html#app-config-compileroptions)
|
|
74
|
+
* @type {typeof import('@kdujs/compiler-core').CompilerOptions}
|
|
75
|
+
*/
|
|
31
76
|
compilerOptions: {}
|
|
32
77
|
},
|
|
78
|
+
/**
|
|
79
|
+
* Dtwo App configuration.
|
|
80
|
+
*/
|
|
33
81
|
app: {
|
|
82
|
+
/**
|
|
83
|
+
* The base path of your Dtwo application.
|
|
84
|
+
*
|
|
85
|
+
* This can be set at runtime by setting the DTWO_APP_BASE_URL environment variable.
|
|
86
|
+
* @example
|
|
87
|
+
* ```bash
|
|
88
|
+
* DTWO_APP_BASE_URL=/prefix/ node .output/server/index.mjs
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
34
91
|
baseURL: {
|
|
35
92
|
$resolve: async (val) => val || process.env.DTWO_APP_BASE_URL || "/"
|
|
36
93
|
},
|
|
94
|
+
/** The folder name for the built site assets, relative to `baseURL` (or `cdnURL` if set). This is set at build time and should not be customized at runtime. */
|
|
37
95
|
buildAssetsDir: {
|
|
38
96
|
$resolve: async (val) => val || process.env.DTWO_APP_BUILD_ASSETS_DIR || "/_dtwo/"
|
|
39
97
|
},
|
|
98
|
+
/**
|
|
99
|
+
* An absolute URL to serve the public folder from (production-only).
|
|
100
|
+
*
|
|
101
|
+
* This can be set to a different value at runtime by setting the `DTWO_APP_CDN_URL` environment variable.
|
|
102
|
+
* @example
|
|
103
|
+
* ```bash
|
|
104
|
+
* DTWO_APP_CDN_URL=https://mycdn.org/ node .output/server/index.mjs
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
40
107
|
cdnURL: {
|
|
41
108
|
$resolve: async (val, get) => await get("dev") ? "" : (process.env.DTWO_APP_CDN_URL ?? val) || ""
|
|
42
109
|
},
|
|
110
|
+
/**
|
|
111
|
+
* Set default configuration for `<head>` on every page.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```js
|
|
115
|
+
* app: {
|
|
116
|
+
* head: {
|
|
117
|
+
* meta: [
|
|
118
|
+
* // <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
119
|
+
* { name: 'viewport', content: 'width=device-width, initial-scale=1' }
|
|
120
|
+
* ],
|
|
121
|
+
* script: [
|
|
122
|
+
* // <script src="https://myawesome-lib.js"><\/script>
|
|
123
|
+
* { src: 'https://awesome-lib.js' }
|
|
124
|
+
* ],
|
|
125
|
+
* link: [
|
|
126
|
+
* // <link rel="stylesheet" href="https://myawesome-lib.css">
|
|
127
|
+
* { rel: 'stylesheet', href: 'https://awesome-lib.css' }
|
|
128
|
+
* ],
|
|
129
|
+
* // please note that this is an area that is likely to change
|
|
130
|
+
* style: [
|
|
131
|
+
* // <style type="text/css">:root { color: red }</style>
|
|
132
|
+
* { children: ':root { color: red }', type: 'text/css' }
|
|
133
|
+
* ],
|
|
134
|
+
* noscript: [
|
|
135
|
+
* // <noscript>JavaScript is required</noscript>
|
|
136
|
+
* { children: 'JavaScript is required' }
|
|
137
|
+
* ]
|
|
138
|
+
* }
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
* @type {typeof import('../src/types/config').DtwoAppConfig['head']}
|
|
142
|
+
*/
|
|
43
143
|
head: {
|
|
44
144
|
$resolve: async (val, get) => {
|
|
45
145
|
const resolved = defu(val, await get("meta"), {
|
|
@@ -63,19 +163,107 @@ const app = defineUntypedSchema({
|
|
|
63
163
|
return resolved;
|
|
64
164
|
}
|
|
65
165
|
},
|
|
166
|
+
/**
|
|
167
|
+
* Default values for layout transitions.
|
|
168
|
+
*
|
|
169
|
+
* This can be overridden with `definePageMeta` on an individual page.
|
|
170
|
+
* Only JSON-serializable values are allowed.
|
|
171
|
+
*
|
|
172
|
+
* @see https://kdu-js.web.app/api/built-in-components.html#transition
|
|
173
|
+
* @type {typeof import('../src/types/config').DtwoAppConfig['layoutTransition']}
|
|
174
|
+
*/
|
|
66
175
|
layoutTransition: false,
|
|
176
|
+
/**
|
|
177
|
+
* Default values for page transitions.
|
|
178
|
+
*
|
|
179
|
+
* This can be overridden with `definePageMeta` on an individual page.
|
|
180
|
+
* Only JSON-serializable values are allowed.
|
|
181
|
+
*
|
|
182
|
+
* @see https://kdu-js.web.app/api/built-in-components.html#transition
|
|
183
|
+
* @type {typeof import('../src/types/config').DtwoAppConfig['pageTransition']}
|
|
184
|
+
*/
|
|
67
185
|
pageTransition: false,
|
|
186
|
+
/**
|
|
187
|
+
* Default values for KeepAlive configuration between pages.
|
|
188
|
+
*
|
|
189
|
+
* This can be overridden with `definePageMeta` on an individual page.
|
|
190
|
+
* Only JSON-serializable values are allowed.
|
|
191
|
+
*
|
|
192
|
+
* @see https://kdu-js.web.app/api/built-in-components.html#keepalive
|
|
193
|
+
* @type {typeof import('../src/types/config').DtwoAppConfig['keepalive']}
|
|
194
|
+
*/
|
|
68
195
|
keepalive: false,
|
|
196
|
+
/**
|
|
197
|
+
* Customize Dtwo root element id.
|
|
198
|
+
*/
|
|
69
199
|
rootId: "__dtwo",
|
|
200
|
+
/**
|
|
201
|
+
* Customize Dtwo root element tag.
|
|
202
|
+
*
|
|
203
|
+
*/
|
|
70
204
|
rootTag: "div"
|
|
71
205
|
},
|
|
206
|
+
/**
|
|
207
|
+
* An array of dtwo app plugins.
|
|
208
|
+
*
|
|
209
|
+
* Each plugin can be a string (which can be an absolute or relative path to a file).
|
|
210
|
+
* If it ends with `.client` or `.server` then it will be automatically loaded only
|
|
211
|
+
* in the appropriate context.
|
|
212
|
+
*
|
|
213
|
+
* It can also be an object with `src` and `mode` keys.
|
|
214
|
+
*
|
|
215
|
+
* @note Plugins are also auto-registered from the `~/plugins` directory
|
|
216
|
+
* and these plugins do not need to be listed in `dtwo.config` unless you
|
|
217
|
+
* need to customize their order. All plugins are deduplicated by their src path.
|
|
218
|
+
*
|
|
219
|
+
* @see https://dtwojs.web.app/docs/guide/directory-structure/plugins
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```js
|
|
223
|
+
* plugins: [
|
|
224
|
+
* '~/plugins/foo.client.js', // only in client side
|
|
225
|
+
* '~/plugins/bar.server.js', // only in server side
|
|
226
|
+
* '~/plugins/baz.js', // both client & server
|
|
227
|
+
* { src: '~/plugins/both-sides.js' },
|
|
228
|
+
* { src: '~/plugins/client-only.js', mode: 'client' }, // only on client side
|
|
229
|
+
* { src: '~/plugins/server-only.js', mode: 'server' } // only on server side
|
|
230
|
+
* ]
|
|
231
|
+
* ```
|
|
232
|
+
* @type {(typeof import('../src/types/dtwo').DtwoPlugin | string)[]}
|
|
233
|
+
*/
|
|
72
234
|
plugins: [],
|
|
235
|
+
/**
|
|
236
|
+
* You can define the CSS files/modules/libraries you want to set globally
|
|
237
|
+
* (included in every page).
|
|
238
|
+
*
|
|
239
|
+
* Dtwo will automatically guess the file type by its extension and use the
|
|
240
|
+
* appropriate pre-processor. You will still need to install the required
|
|
241
|
+
* loader if you need to use them.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```js
|
|
245
|
+
* css: [
|
|
246
|
+
* // Load a Node.js module directly (here it's a Sass file).
|
|
247
|
+
* 'bulma',
|
|
248
|
+
* // CSS file in the project
|
|
249
|
+
* '@/assets/css/main.css',
|
|
250
|
+
* // SCSS file in the project
|
|
251
|
+
* '@/assets/css/main.scss'
|
|
252
|
+
* ]
|
|
253
|
+
* ```
|
|
254
|
+
* @type {string[]}
|
|
255
|
+
*/
|
|
73
256
|
css: {
|
|
74
257
|
$resolve: (val) => (val ?? []).map((c) => c.src || c)
|
|
75
258
|
}
|
|
76
259
|
});
|
|
77
260
|
|
|
78
261
|
const build = defineUntypedSchema({
|
|
262
|
+
/**
|
|
263
|
+
* The builder to use for bundling the Kdu part of your application.
|
|
264
|
+
*
|
|
265
|
+
* @type {'wite' | 'webpack' | { bundle: (dtwo: typeof import('../src/types/dtwo').Dtwo) => Promise<void> }}
|
|
266
|
+
*/
|
|
79
267
|
builder: {
|
|
80
268
|
$resolve: async (val, get) => {
|
|
81
269
|
if (typeof val === "object") {
|
|
@@ -88,6 +276,11 @@ const build = defineUntypedSchema({
|
|
|
88
276
|
return map[val] || val || (await get("wite") === false ? map.webpack : map.wite);
|
|
89
277
|
}
|
|
90
278
|
},
|
|
279
|
+
/**
|
|
280
|
+
* Whether to generate sourcemaps.
|
|
281
|
+
*
|
|
282
|
+
* @type {boolean | { server?: boolean, client?: boolean }}
|
|
283
|
+
*/
|
|
91
284
|
sourcemap: {
|
|
92
285
|
$resolve: async (val, get) => {
|
|
93
286
|
if (typeof val === "boolean") {
|
|
@@ -99,11 +292,61 @@ const build = defineUntypedSchema({
|
|
|
99
292
|
});
|
|
100
293
|
}
|
|
101
294
|
},
|
|
295
|
+
/**
|
|
296
|
+
* Shared build configuration.
|
|
297
|
+
*/
|
|
102
298
|
build: {
|
|
299
|
+
/**
|
|
300
|
+
* If you want to transpile specific dependencies with Babel, you can add them here.
|
|
301
|
+
* Each item in transpile can be a package name, a function, a string or regex object matching the
|
|
302
|
+
* dependency's file name.
|
|
303
|
+
*
|
|
304
|
+
* You can also use a function to conditionally transpile. The function will receive an object ({ isDev, isServer, isClient, isModern, isLegacy }).
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```js
|
|
308
|
+
transpile: [({ isLegacy }) => isLegacy && 'ky']
|
|
309
|
+
* ```
|
|
310
|
+
* @type {Array<string | RegExp | ((ctx: { isClient?: boolean; isServer?: boolean; isDev: boolean }) => string | RegExp | false)>}
|
|
311
|
+
*/
|
|
103
312
|
transpile: {
|
|
104
313
|
$resolve: (val) => [].concat(val).filter(Boolean)
|
|
105
314
|
},
|
|
315
|
+
/**
|
|
316
|
+
* You can provide your own templates which will be rendered based
|
|
317
|
+
* on Dtwo configuration. This feature is specially useful for using with modules.
|
|
318
|
+
*
|
|
319
|
+
* Templates are rendered using [`lodash.template`](https://lodash.com/docs/4.17.15#template).
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```js
|
|
323
|
+
* templates: [
|
|
324
|
+
* {
|
|
325
|
+
* src: '~/modules/support/plugin.js', // `src` can be absolute or relative
|
|
326
|
+
* dst: 'support.js', // `dst` is relative to project `.dtwo` dir
|
|
327
|
+
* options: {
|
|
328
|
+
* // Options are provided to template as `options` key
|
|
329
|
+
* live_chat: false
|
|
330
|
+
* }
|
|
331
|
+
* }
|
|
332
|
+
* ]
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
106
335
|
templates: [],
|
|
336
|
+
/**
|
|
337
|
+
* Dtwo uses `webpack-bundle-analyzer` to visualize your bundles and how to optimize them.
|
|
338
|
+
*
|
|
339
|
+
* Set to `true` to enable bundle analysis, or pass an object with options: [for webpack](https://github.com/webpack-contrib/webpack-bundle-analyzer#options-for-plugin) or [for wite](https://github.com/btd/rollup-plugin-visualizer#options).
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```js
|
|
343
|
+
* analyze: {
|
|
344
|
+
* analyzerMode: 'static'
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
* @type {boolean | typeof import('webpack-bundle-analyzer').BundleAnalyzerPlugin.Options | typeof import('rollup-plugin-visualizer').PluginVisualizerOptions}
|
|
348
|
+
*
|
|
349
|
+
*/
|
|
107
350
|
analyze: {
|
|
108
351
|
$resolve: async (val, get) => {
|
|
109
352
|
if (val !== true) {
|
|
@@ -121,23 +364,124 @@ const build = defineUntypedSchema({
|
|
|
121
364
|
});
|
|
122
365
|
|
|
123
366
|
const common = defineUntypedSchema({
|
|
367
|
+
/**
|
|
368
|
+
* Extend project from multiple local or remote sources.
|
|
369
|
+
*
|
|
370
|
+
* Value should be either a string or array of strings pointing to source directories or config path relative to current config.
|
|
371
|
+
*
|
|
372
|
+
* You can use `github:`, `gitlab:`, `bitbucket:` or `https://` to extend from a remote git repository.
|
|
373
|
+
*
|
|
374
|
+
* @type {string|string[]}
|
|
375
|
+
*
|
|
376
|
+
*/
|
|
124
377
|
extends: null,
|
|
378
|
+
/**
|
|
379
|
+
* Extend project from a local or remote source.
|
|
380
|
+
*
|
|
381
|
+
* Value should be a string pointing to source directory or config path relative to current config.
|
|
382
|
+
*
|
|
383
|
+
* You can use `github:`, `gitlab:`, `bitbucket:` or `https://` to extend from a remote git repository.
|
|
384
|
+
*
|
|
385
|
+
* @type {string}
|
|
386
|
+
*
|
|
387
|
+
*/
|
|
125
388
|
theme: null,
|
|
389
|
+
/**
|
|
390
|
+
* Define the root directory of your application.
|
|
391
|
+
*
|
|
392
|
+
* This property can be overwritten (for example, running `dtwo ./my-app/`
|
|
393
|
+
* will set the `rootDir` to the absolute path of `./my-app/` from the
|
|
394
|
+
* current/working directory.
|
|
395
|
+
*
|
|
396
|
+
* It is normally not needed to configure this option.
|
|
397
|
+
*/
|
|
126
398
|
rootDir: {
|
|
127
399
|
$resolve: (val) => typeof val === "string" ? resolve(val) : process.cwd()
|
|
128
400
|
},
|
|
401
|
+
/**
|
|
402
|
+
* Define the workspace directory of your application.
|
|
403
|
+
*
|
|
404
|
+
* Often this is used when in a monorepo setup. Dtwo will attempt to detect
|
|
405
|
+
* your workspace directory automatically, but you can override it here.
|
|
406
|
+
*
|
|
407
|
+
* It is normally not needed to configure this option.
|
|
408
|
+
*/
|
|
129
409
|
workspaceDir: {
|
|
130
410
|
$resolve: async (val, get) => val ? resolve(await get("rootDir"), val) : await findWorkspaceDir(await get("rootDir")).catch(() => get("rootDir"))
|
|
131
411
|
},
|
|
412
|
+
/**
|
|
413
|
+
* Define the source directory of your Dtwo application.
|
|
414
|
+
*
|
|
415
|
+
* If a relative path is specified, it will be relative to the `rootDir`.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```js
|
|
419
|
+
* export default {
|
|
420
|
+
* srcDir: 'src/'
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
* This would work with the following folder structure:
|
|
424
|
+
* ```bash
|
|
425
|
+
* -| app/
|
|
426
|
+
* ---| node_modules/
|
|
427
|
+
* ---| dtwo.config.js
|
|
428
|
+
* ---| package.json
|
|
429
|
+
* ---| src/
|
|
430
|
+
* ------| assets/
|
|
431
|
+
* ------| components/
|
|
432
|
+
* ------| layouts/
|
|
433
|
+
* ------| middleware/
|
|
434
|
+
* ------| pages/
|
|
435
|
+
* ------| plugins/
|
|
436
|
+
* ------| static/
|
|
437
|
+
* ------| store/
|
|
438
|
+
* ------| server/
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
132
441
|
srcDir: {
|
|
133
442
|
$resolve: async (val, get) => resolve(await get("rootDir"), val || ".")
|
|
134
443
|
},
|
|
444
|
+
/**
|
|
445
|
+
* Define the server directory of your Dtwo application, where Hole
|
|
446
|
+
* routes, middleware and plugins are kept.
|
|
447
|
+
*
|
|
448
|
+
* If a relative path is specified, it will be relative to your `rootDir`.
|
|
449
|
+
*
|
|
450
|
+
*/
|
|
135
451
|
serverDir: {
|
|
136
452
|
$resolve: async (val, get) => resolve(await get("rootDir"), val || resolve(await get("srcDir"), "server"))
|
|
137
453
|
},
|
|
454
|
+
/**
|
|
455
|
+
* Define the directory where your built Dtwo files will be placed.
|
|
456
|
+
*
|
|
457
|
+
* Many tools assume that `.dtwo` is a hidden directory (because it starts
|
|
458
|
+
* with a `.`). If that is a problem, you can use this option to prevent that.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```js
|
|
462
|
+
* export default {
|
|
463
|
+
* buildDir: 'dtwo-build'
|
|
464
|
+
* }
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
138
467
|
buildDir: {
|
|
139
468
|
$resolve: async (val, get) => resolve(await get("rootDir"), val || ".dtwo")
|
|
140
469
|
},
|
|
470
|
+
/**
|
|
471
|
+
* Used to set the modules directories for path resolving (for example, webpack's
|
|
472
|
+
* `resolveLoading`, `nodeExternals` and `postcss`).
|
|
473
|
+
*
|
|
474
|
+
* The configuration path is relative to `options.rootDir` (default is current working directory).
|
|
475
|
+
*
|
|
476
|
+
* Setting this field may be necessary if your project is organized as a yarn workspace-styled mono-repository.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```js
|
|
480
|
+
* export default {
|
|
481
|
+
* modulesDir: ['../../node_modules']
|
|
482
|
+
* }
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
141
485
|
modulesDir: {
|
|
142
486
|
$default: ["node_modules"],
|
|
143
487
|
$resolve: async (val, get) => [
|
|
@@ -145,21 +489,91 @@ const common = defineUntypedSchema({
|
|
|
145
489
|
resolve(process.cwd(), "node_modules")
|
|
146
490
|
]
|
|
147
491
|
},
|
|
492
|
+
/**
|
|
493
|
+
* Whether Dtwo is running in development mode.
|
|
494
|
+
*
|
|
495
|
+
* Normally, you should not need to set this.
|
|
496
|
+
*/
|
|
148
497
|
dev: Boolean(isDevelopment),
|
|
498
|
+
/**
|
|
499
|
+
* Whether your app is being unit tested.
|
|
500
|
+
*/
|
|
149
501
|
test: Boolean(isDevelopment),
|
|
502
|
+
/**
|
|
503
|
+
* Set to `true` to enable debug mode.
|
|
504
|
+
*
|
|
505
|
+
* At the moment, it prints out hook names and timings on the server, and
|
|
506
|
+
* logs hook arguments as well in the browser.
|
|
507
|
+
*
|
|
508
|
+
*/
|
|
150
509
|
debug: {
|
|
151
510
|
$resolve: async (val, get) => val ?? isDebug
|
|
152
511
|
},
|
|
512
|
+
/**
|
|
513
|
+
* Whether to enable rendering of HTML - either dynamically (in server mode) or at generate time.
|
|
514
|
+
* If set to `false` and combined with `static` target, generated pages will simply display
|
|
515
|
+
* a loading screen with no content.
|
|
516
|
+
*/
|
|
153
517
|
ssr: {
|
|
154
518
|
$resolve: (val) => val ?? true
|
|
155
519
|
},
|
|
520
|
+
/**
|
|
521
|
+
* Modules are Dtwo extensions which can extend its core functionality and add endless integrations.
|
|
522
|
+
*
|
|
523
|
+
* Each module is either a string (which can refer to a package, or be a path to a file), a
|
|
524
|
+
* tuple with the module as first string and the options as a second object, or an inline module function.
|
|
525
|
+
*
|
|
526
|
+
* Dtwo tries to resolve each item in the modules array using node require path
|
|
527
|
+
* (in `node_modules`) and then will be resolved from project `srcDir` if `~` alias is used.
|
|
528
|
+
*
|
|
529
|
+
* @note Modules are executed sequentially so the order is important.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```js
|
|
533
|
+
* modules: [
|
|
534
|
+
* // Using package name
|
|
535
|
+
* '@dtwojs/axios',
|
|
536
|
+
* // Relative to your project srcDir
|
|
537
|
+
* '~/modules/awesome.js',
|
|
538
|
+
* // Providing options
|
|
539
|
+
* ['@dtwojs/google-analytics', { ua: 'X1234567' }],
|
|
540
|
+
* // Inline definition
|
|
541
|
+
* function () {}
|
|
542
|
+
* ]
|
|
543
|
+
* ```
|
|
544
|
+
* @type {(typeof import('../src/types/module').DtwoModule | string | [typeof import('../src/types/module').DtwoModule | string, Record<string, any>])[]}
|
|
545
|
+
*/
|
|
156
546
|
modules: [],
|
|
547
|
+
/**
|
|
548
|
+
* Customize default directory structure used by Dtwo.
|
|
549
|
+
*
|
|
550
|
+
* It is better to stick with defaults unless needed.
|
|
551
|
+
*/
|
|
157
552
|
dir: {
|
|
553
|
+
/**
|
|
554
|
+
* The assets directory (aliased as `~assets` in your build).
|
|
555
|
+
*/
|
|
158
556
|
assets: "assets",
|
|
557
|
+
/**
|
|
558
|
+
* The layouts directory, each file of which will be auto-registered as a Dtwo layout.
|
|
559
|
+
*/
|
|
159
560
|
layouts: "layouts",
|
|
561
|
+
/**
|
|
562
|
+
* The middleware directory, each file of which will be auto-registered as a Dtwo middleware.
|
|
563
|
+
*/
|
|
160
564
|
middleware: "middleware",
|
|
565
|
+
/**
|
|
566
|
+
* The directory which will be processed to auto-generate your application page routes.
|
|
567
|
+
*/
|
|
161
568
|
pages: "pages",
|
|
569
|
+
/**
|
|
570
|
+
* The plugins directory, each file of which will be auto-registered as a Dtwo plugin.
|
|
571
|
+
*/
|
|
162
572
|
plugins: "plugins",
|
|
573
|
+
/**
|
|
574
|
+
* The directory containing your static files, which will be directly accessible via the Dtwo server
|
|
575
|
+
* and copied across into your `dist` folder when your app is generated.
|
|
576
|
+
*/
|
|
163
577
|
public: {
|
|
164
578
|
$resolve: async (val, get) => val || await get("dir.static") || "public"
|
|
165
579
|
},
|
|
@@ -168,9 +582,56 @@ const common = defineUntypedSchema({
|
|
|
168
582
|
$resolve: async (val, get) => val || await get("dir.public") || "public"
|
|
169
583
|
}
|
|
170
584
|
},
|
|
585
|
+
/**
|
|
586
|
+
* The extensions that should be resolved by the Dtwo resolver.
|
|
587
|
+
*/
|
|
171
588
|
extensions: {
|
|
172
589
|
$resolve: (val) => [".js", ".jsx", ".mjs", ".ts", ".tsx", ".kdu"].concat(val).filter(Boolean)
|
|
173
590
|
},
|
|
591
|
+
/**
|
|
592
|
+
* You can improve your DX by defining additional aliases to access custom directories
|
|
593
|
+
* within your JavaScript and CSS.
|
|
594
|
+
*
|
|
595
|
+
* @note Within a webpack context (image sources, CSS - but not JavaScript) you _must_ access
|
|
596
|
+
* your alias by prefixing it with `~`.
|
|
597
|
+
*
|
|
598
|
+
* @note These aliases will be automatically added to the generated `.dtwo/tsconfig.json` so you can get full
|
|
599
|
+
* type support and path auto-complete. In case you need to extend options provided by `./.dtwo/tsconfig.json`
|
|
600
|
+
* further, make sure to add them here or within the `typescript.tsConfig` property in `dtwo.config`.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```js
|
|
604
|
+
* export default {
|
|
605
|
+
* alias: {
|
|
606
|
+
* 'images': fileURLToPath(new URL('./assets/images', import.meta.url)),
|
|
607
|
+
* 'style': fileURLToPath(new URL('./assets/style', import.meta.url)),
|
|
608
|
+
* 'data': fileURLToPath(new URL('./assets/other/data', import.meta.url))
|
|
609
|
+
* }
|
|
610
|
+
* }
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* ```html
|
|
614
|
+
* <template>
|
|
615
|
+
* <img src="~images/main-bg.jpg">
|
|
616
|
+
* </template>
|
|
617
|
+
*
|
|
618
|
+
* <script>
|
|
619
|
+
* import data from 'data/test.json'
|
|
620
|
+
* <\/script>
|
|
621
|
+
*
|
|
622
|
+
* <style>
|
|
623
|
+
* // Uncomment the below
|
|
624
|
+
* //@import '~style/variables.scss';
|
|
625
|
+
* //@import '~style/utils.scss';
|
|
626
|
+
* //@import '~style/base.scss';
|
|
627
|
+
* body {
|
|
628
|
+
* background-image: url('~images/main-bg.jpg');
|
|
629
|
+
* }
|
|
630
|
+
* </style>
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @type {Record<string, string>}
|
|
634
|
+
*/
|
|
174
635
|
alias: {
|
|
175
636
|
$resolve: async (val, get) => ({
|
|
176
637
|
"~~": await get("rootDir"),
|
|
@@ -182,30 +643,122 @@ const common = defineUntypedSchema({
|
|
|
182
643
|
...val
|
|
183
644
|
})
|
|
184
645
|
},
|
|
646
|
+
/**
|
|
647
|
+
* Pass options directly to `node-ignore` (which is used by Dtwo to ignore files).
|
|
648
|
+
*
|
|
649
|
+
* @see [node-ignore](https://github.com/kaelzhang/node-ignore)
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```js
|
|
653
|
+
* ignoreOptions: {
|
|
654
|
+
* ignorecase: false
|
|
655
|
+
* }
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
185
658
|
ignoreOptions: void 0,
|
|
659
|
+
/**
|
|
660
|
+
* Any file in `pages/`, `layouts/`, `middleware/` or `store/` will be ignored during
|
|
661
|
+
* building if its filename starts with the prefix specified by `ignorePrefix`.
|
|
662
|
+
*/
|
|
186
663
|
ignorePrefix: "-",
|
|
664
|
+
/**
|
|
665
|
+
* More customizable than `ignorePrefix`: all files matching glob patterns specified
|
|
666
|
+
* inside the `ignore` array will be ignored in building.
|
|
667
|
+
*/
|
|
187
668
|
ignore: {
|
|
188
669
|
$resolve: async (val, get) => [
|
|
189
670
|
"**/*.stories.{js,ts,jsx,tsx}",
|
|
671
|
+
// ignore storybook files
|
|
190
672
|
"**/*.{spec,test}.{js,ts,jsx,tsx}",
|
|
673
|
+
// ignore tests
|
|
191
674
|
"**/*.d.ts",
|
|
675
|
+
// ignore type declarations
|
|
192
676
|
".output",
|
|
193
677
|
await get("ignorePrefix") && `**/${await get("ignorePrefix")}*.*`
|
|
194
678
|
].concat(val).filter(Boolean)
|
|
195
679
|
},
|
|
680
|
+
/**
|
|
681
|
+
* The watchers property lets you overwrite watchers configuration in your `dtwo.config`.
|
|
682
|
+
*/
|
|
196
683
|
watchers: {
|
|
684
|
+
/** An array of event types, which, when received, will cause the watcher to restart. */
|
|
197
685
|
rewatchOnRawEvents: void 0,
|
|
686
|
+
/**
|
|
687
|
+
* `watchOptions` to pass directly to webpack.
|
|
688
|
+
*
|
|
689
|
+
* @see [webpack@4 watch options](https://v4.webpack.js.org/configuration/watch/#watchoptions).
|
|
690
|
+
* */
|
|
198
691
|
webpack: {
|
|
199
692
|
aggregateTimeout: 1e3
|
|
200
693
|
},
|
|
694
|
+
/**
|
|
695
|
+
* Options to pass directly to `chokidar`.
|
|
696
|
+
*
|
|
697
|
+
* @see [chokidar](https://github.com/paulmillr/chokidar#api)
|
|
698
|
+
*/
|
|
201
699
|
chokidar: {
|
|
202
700
|
ignoreInitial: true
|
|
203
701
|
}
|
|
204
702
|
},
|
|
703
|
+
/**
|
|
704
|
+
* Hooks are listeners to Dtwo events that are typically used in modules,
|
|
705
|
+
* but are also available in `dtwo.config`.
|
|
706
|
+
*
|
|
707
|
+
* Internally, hooks follow a naming pattern using colons (e.g., build:done).
|
|
708
|
+
*
|
|
709
|
+
* For ease of configuration, you can also structure them as an hierarchical
|
|
710
|
+
* object in `dtwo.config` (as below).
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```js'node:fs'
|
|
714
|
+
* import fs from 'node:fs'
|
|
715
|
+
* import path from 'node:path'
|
|
716
|
+
* export default {
|
|
717
|
+
* hooks: {
|
|
718
|
+
* build: {
|
|
719
|
+
* done(builder) {
|
|
720
|
+
* const extraFilePath = path.join(
|
|
721
|
+
* builder.dtwo.options.buildDir,
|
|
722
|
+
* 'extra-file'
|
|
723
|
+
* )
|
|
724
|
+
* fs.writeFileSync(extraFilePath, 'Something extra')
|
|
725
|
+
* }
|
|
726
|
+
* }
|
|
727
|
+
* }
|
|
728
|
+
* }
|
|
729
|
+
* ```
|
|
730
|
+
* @type {typeof import('../src/types/hooks').DtwoHooks}
|
|
731
|
+
*/
|
|
205
732
|
hooks: null,
|
|
733
|
+
/**
|
|
734
|
+
* Runtime config allows passing dynamic config and environment variables to the Dtwo app context.
|
|
735
|
+
*
|
|
736
|
+
* The value of this object is accessible from server only using `useRuntimeConfig`.
|
|
737
|
+
*
|
|
738
|
+
* It mainly should hold _private_ configuration which is not exposed on the frontend.
|
|
739
|
+
* This could include a reference to your API secret tokens.
|
|
740
|
+
*
|
|
741
|
+
* Anything under `public` and `app` will be exposed to the frontend as well.
|
|
742
|
+
*
|
|
743
|
+
* Values are automatically replaced by matching env variables at runtime, e.g. setting an environment
|
|
744
|
+
* variable `DTWO_API_KEY=my-api-key DTWO_PUBLIC_BASE_URL=/foo/` would overwrite the two values in the example below.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```js
|
|
748
|
+
* export default {
|
|
749
|
+
* runtimeConfig: {
|
|
750
|
+
* apiKey: '' // Default to an empty string, automatically set at runtime using process.env.DTWO_API_KEY
|
|
751
|
+
* public: {
|
|
752
|
+
* baseURL: '' // Exposed to the frontend as well.
|
|
753
|
+
* }
|
|
754
|
+
* }
|
|
755
|
+
* }
|
|
756
|
+
* ```
|
|
757
|
+
* @type {typeof import('../src/types/config').RuntimeConfig}
|
|
758
|
+
*/
|
|
206
759
|
runtimeConfig: {
|
|
207
760
|
$resolve: async (val, get) => defu(val, {
|
|
208
|
-
public:
|
|
761
|
+
public: {},
|
|
209
762
|
app: {
|
|
210
763
|
baseURL: (await get("app")).baseURL,
|
|
211
764
|
buildAssetsDir: (await get("app")).buildAssetsDir,
|
|
@@ -213,26 +766,78 @@ const common = defineUntypedSchema({
|
|
|
213
766
|
}
|
|
214
767
|
})
|
|
215
768
|
},
|
|
216
|
-
|
|
769
|
+
/**
|
|
770
|
+
* Additional app configuration
|
|
771
|
+
*
|
|
772
|
+
* For programmatic usage and type support, you can directly provide app config with this option.
|
|
773
|
+
* It will be merged with `app.config` file as default value.
|
|
774
|
+
*
|
|
775
|
+
* @type {typeof import('../src/types/config').AppConfig}
|
|
776
|
+
*/
|
|
777
|
+
appConfig: {},
|
|
778
|
+
$schema: {}
|
|
217
779
|
});
|
|
218
780
|
|
|
219
781
|
const dev = defineUntypedSchema({
|
|
220
782
|
devServer: {
|
|
783
|
+
/**
|
|
784
|
+
* Whether to enable HTTPS.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```
|
|
788
|
+
* import { fileURLToPath } from 'node:url'
|
|
789
|
+
* export default {
|
|
790
|
+
* server: {
|
|
791
|
+
* https: {
|
|
792
|
+
* key: fs.readFileSync(fileURLToPath(new URL('./server.key', import.meta.url))),
|
|
793
|
+
* cert: fs.readFileSync(fileURLToPath(new URL('./server.crt', import.meta.url)))
|
|
794
|
+
* }
|
|
795
|
+
* }
|
|
796
|
+
* }
|
|
797
|
+
* ```
|
|
798
|
+
*
|
|
799
|
+
*
|
|
800
|
+
* @type {false | { key: string; cert: string }}
|
|
801
|
+
*
|
|
802
|
+
*/
|
|
221
803
|
https: false,
|
|
804
|
+
/** Dev server listening port */
|
|
222
805
|
port: process.env.DTWO_PORT || process.env.HOLE_PORT || process.env.PORT || 3e3,
|
|
806
|
+
/** Dev server listening host */
|
|
223
807
|
host: process.env.DTWO_HOST || process.env.HOLE_HOST || process.env.HOST || "localhost",
|
|
808
|
+
/**
|
|
809
|
+
* Listening dev server url
|
|
810
|
+
*/
|
|
224
811
|
url: "http://localhost:3000"
|
|
225
812
|
}
|
|
226
813
|
});
|
|
227
814
|
|
|
228
815
|
const experimental = defineUntypedSchema({
|
|
229
816
|
experimental: {
|
|
817
|
+
/**
|
|
818
|
+
* Set to true to generate an async entry point for the Kdu bundle (for module federation support).
|
|
819
|
+
*/
|
|
230
820
|
asyncEntry: {
|
|
231
821
|
$resolve: (val) => val ?? false
|
|
232
822
|
},
|
|
823
|
+
/**
|
|
824
|
+
* Enable Kdu's reactivity transform
|
|
825
|
+
* @see https://kdu-js.web.app/guide/extras/reactivity-transform.html
|
|
826
|
+
*/
|
|
233
827
|
reactivityTransform: false,
|
|
828
|
+
/**
|
|
829
|
+
* Externalize `kdu`, `@kdujs/*` and `kdu-router` when building.
|
|
830
|
+
*/
|
|
234
831
|
externalKdu: true,
|
|
832
|
+
/**
|
|
833
|
+
* Tree shakes contents of client-only components from server bundle.
|
|
834
|
+
*/
|
|
235
835
|
treeshakeClientOnly: true,
|
|
836
|
+
/**
|
|
837
|
+
* Use wite-node for on-demand server chunk loading
|
|
838
|
+
*
|
|
839
|
+
* @deprecated use `wite.devBundler: 'wite-node'`
|
|
840
|
+
*/
|
|
236
841
|
witeNode: {
|
|
237
842
|
$resolve: (val) => {
|
|
238
843
|
val = process.env.EXPERIMENTAL_WITE_NODE ? true : val;
|
|
@@ -244,7 +849,18 @@ const experimental = defineUntypedSchema({
|
|
|
244
849
|
return val ?? true;
|
|
245
850
|
}
|
|
246
851
|
},
|
|
852
|
+
/**
|
|
853
|
+
* Split server bundle into multiple chunks and dynamically import them.
|
|
854
|
+
*/
|
|
247
855
|
witeServerDynamicImports: true,
|
|
856
|
+
/**
|
|
857
|
+
* Inline styles when rendering HTML (currently wite only).
|
|
858
|
+
*
|
|
859
|
+
* You can also pass a function that receives the path of a Kdu component
|
|
860
|
+
* and returns a boolean indicating whether to inline the styles for that component.
|
|
861
|
+
*
|
|
862
|
+
* @type {boolean | ((id?: string) => boolean)}
|
|
863
|
+
*/
|
|
248
864
|
inlineSSRStyles: {
|
|
249
865
|
async $resolve(val, get) {
|
|
250
866
|
if (val === false || await get("dev") || await get("ssr") === false || await get("builder") === "@dtwo/webpack-builder") {
|
|
@@ -253,7 +869,13 @@ const experimental = defineUntypedSchema({
|
|
|
253
869
|
return val ?? true;
|
|
254
870
|
}
|
|
255
871
|
},
|
|
872
|
+
/**
|
|
873
|
+
* Turn off rendering of Dtwo scripts and JS resource hints.
|
|
874
|
+
*/
|
|
256
875
|
noScripts: false,
|
|
876
|
+
/**
|
|
877
|
+
* When this option is enabled (by default) payload of pages generated with `dtwo generate` are extracted
|
|
878
|
+
*/
|
|
257
879
|
payloadExtraction: {
|
|
258
880
|
async $resolve(enabled, get) {
|
|
259
881
|
enabled = enabled ?? false;
|
|
@@ -263,35 +885,85 @@ const experimental = defineUntypedSchema({
|
|
|
263
885
|
return enabled;
|
|
264
886
|
}
|
|
265
887
|
},
|
|
888
|
+
/** Enable cross-origin prefetch using the Speculation Rules API. */
|
|
266
889
|
crossOriginPrefetch: false,
|
|
267
|
-
|
|
890
|
+
/**
|
|
891
|
+
* Write early hints when using node server.
|
|
892
|
+
*
|
|
893
|
+
* @note nginx does not support 103 Early hints in the current version.
|
|
894
|
+
*/
|
|
895
|
+
writeEarlyHints: false,
|
|
896
|
+
/**
|
|
897
|
+
* Experimental component islands support with <DtwoIsland> and .island.kdu files.
|
|
898
|
+
*/
|
|
899
|
+
componentIslands: false,
|
|
900
|
+
/**
|
|
901
|
+
* Enable experimental config schema support
|
|
902
|
+
*/
|
|
903
|
+
configSchema: false
|
|
268
904
|
}
|
|
269
905
|
});
|
|
270
906
|
|
|
271
907
|
const generate = defineUntypedSchema({
|
|
272
908
|
generate: {
|
|
909
|
+
/**
|
|
910
|
+
* The routes to generate.
|
|
911
|
+
*
|
|
912
|
+
* If you are using the crawler, this will be only the starting point for route generation.
|
|
913
|
+
* This is often necessary when using dynamic routes.
|
|
914
|
+
*
|
|
915
|
+
* It is preferred to use `hole.prerender.routes`.
|
|
916
|
+
*
|
|
917
|
+
* @example
|
|
918
|
+
* ```js
|
|
919
|
+
* routes: ['/users/1', '/users/2', '/users/3']
|
|
920
|
+
* ```
|
|
921
|
+
*/
|
|
273
922
|
routes: [],
|
|
923
|
+
/**
|
|
924
|
+
* This option is no longer used. Instead, use `hole.prerender.ignore`.
|
|
925
|
+
*/
|
|
274
926
|
exclude: []
|
|
275
927
|
}
|
|
276
928
|
});
|
|
277
929
|
|
|
278
930
|
const internal = defineUntypedSchema({
|
|
931
|
+
/** @private */
|
|
279
932
|
_majorVersion: 3,
|
|
933
|
+
/** @private */
|
|
280
934
|
_legacyGenerate: false,
|
|
935
|
+
/** @private */
|
|
281
936
|
_start: false,
|
|
937
|
+
/** @private */
|
|
282
938
|
_build: false,
|
|
939
|
+
/** @private */
|
|
283
940
|
_generate: false,
|
|
941
|
+
/** @private */
|
|
284
942
|
_prepare: false,
|
|
943
|
+
/** @private */
|
|
285
944
|
_cli: false,
|
|
945
|
+
/** @private */
|
|
286
946
|
_requiredModules: {},
|
|
947
|
+
/** @private */
|
|
287
948
|
_dtwoConfigFile: void 0,
|
|
949
|
+
/** @private */
|
|
288
950
|
_dtwoConfigFiles: [],
|
|
951
|
+
/** @private */
|
|
289
952
|
appDir: "",
|
|
953
|
+
/** @private */
|
|
290
954
|
_installedModules: [],
|
|
955
|
+
/** @private */
|
|
291
956
|
_modules: []
|
|
292
957
|
});
|
|
293
958
|
|
|
294
959
|
const hole = defineUntypedSchema({
|
|
960
|
+
/**
|
|
961
|
+
* Configuration for Hole.
|
|
962
|
+
*
|
|
963
|
+
* @see https://holepack.web.app/config/
|
|
964
|
+
*
|
|
965
|
+
* @type {typeof import('holepack')['HoleConfig']}
|
|
966
|
+
*/
|
|
295
967
|
hole: {
|
|
296
968
|
routeRules: {
|
|
297
969
|
$resolve: async (val, get) => ({
|
|
@@ -300,15 +972,62 @@ const hole = defineUntypedSchema({
|
|
|
300
972
|
})
|
|
301
973
|
}
|
|
302
974
|
},
|
|
975
|
+
/**
|
|
976
|
+
* Global route options applied to matching server routes.
|
|
977
|
+
*
|
|
978
|
+
* @experimental This is an experimental feature and API may change in the future.
|
|
979
|
+
*
|
|
980
|
+
* @see https://holepack.web.app/config/#routes
|
|
981
|
+
*
|
|
982
|
+
* @type {typeof import('holepack')['HoleConfig']['routeRules']}
|
|
983
|
+
*/
|
|
303
984
|
routeRules: {},
|
|
985
|
+
/**
|
|
986
|
+
* Hole server handlers.
|
|
987
|
+
*
|
|
988
|
+
* Each handler accepts the following options:
|
|
989
|
+
* - handler: The path to the file defining the handler.
|
|
990
|
+
* - route: The route under which the handler is available. This follows the conventions of https://github.com/unjs/radix3.
|
|
991
|
+
* - method: The HTTP method of requests that should be handled.
|
|
992
|
+
* - middleware: Specifies whether it is a middleware handler.
|
|
993
|
+
* - lazy: Specifies whether to use lazy loading to import the handler.
|
|
994
|
+
*
|
|
995
|
+
* @see https://dtwojs.web.app/docs/guide/directory-structure/server
|
|
996
|
+
*
|
|
997
|
+
* @note Files from `server/api`, `server/middleware` and `server/routes` will be automatically registered by Dtwo.
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* ```js
|
|
1001
|
+
* serverHandlers: [
|
|
1002
|
+
* { route: '/path/foo/**:name', handler: '~/server/foohandler.ts' }
|
|
1003
|
+
* ]
|
|
1004
|
+
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @type {typeof import('holepack')['HoleEventHandler'][]}
|
|
1007
|
+
*/
|
|
304
1008
|
serverHandlers: [],
|
|
1009
|
+
/**
|
|
1010
|
+
* Hole development-only server handlers.
|
|
1011
|
+
*
|
|
1012
|
+
* @see https://holepack.web.app/guide/introduction/routing
|
|
1013
|
+
*
|
|
1014
|
+
* @type {typeof import('holepack')['HoleDevEventHandler'][]}
|
|
1015
|
+
*/
|
|
305
1016
|
devServerHandlers: []
|
|
306
1017
|
});
|
|
307
1018
|
|
|
308
1019
|
const postcss = defineUntypedSchema({
|
|
309
1020
|
postcss: {
|
|
310
|
-
|
|
1021
|
+
/**
|
|
1022
|
+
* Options for configuring PostCSS plugins.
|
|
1023
|
+
*
|
|
1024
|
+
* https://postcss.org/
|
|
1025
|
+
* @type {Record<string, any>}
|
|
1026
|
+
*/
|
|
311
1027
|
plugins: {
|
|
1028
|
+
/**
|
|
1029
|
+
* https://github.com/postcss/postcss-import
|
|
1030
|
+
*/
|
|
312
1031
|
"postcss-import": {
|
|
313
1032
|
$resolve: async (val, get) => val !== false ? defu(val || {}, {
|
|
314
1033
|
resolve: createResolver({
|
|
@@ -321,11 +1040,18 @@ const postcss = defineUntypedSchema({
|
|
|
321
1040
|
})
|
|
322
1041
|
}) : val
|
|
323
1042
|
},
|
|
1043
|
+
/**
|
|
1044
|
+
* https://github.com/postcss/postcss-url
|
|
1045
|
+
*/
|
|
324
1046
|
"postcss-url": {},
|
|
1047
|
+
/**
|
|
1048
|
+
* https://github.com/postcss/autoprefixer
|
|
1049
|
+
*/
|
|
325
1050
|
autoprefixer: {},
|
|
326
1051
|
cssnano: {
|
|
327
1052
|
$resolve: async (val, get) => val ?? !(await get("dev") && {
|
|
328
1053
|
preset: ["default", {
|
|
1054
|
+
// Keep quotes in font values to prevent from HEX conversion
|
|
329
1055
|
minifyFontValues: { removeQuotes: false }
|
|
330
1056
|
}]
|
|
331
1057
|
})
|
|
@@ -336,21 +1062,72 @@ const postcss = defineUntypedSchema({
|
|
|
336
1062
|
|
|
337
1063
|
const router = defineUntypedSchema({
|
|
338
1064
|
router: {
|
|
1065
|
+
/**
|
|
1066
|
+
* Additional options passed to `kdu-router`.
|
|
1067
|
+
*
|
|
1068
|
+
* Note: Only JSON serializable options should be passed by dtwo config.
|
|
1069
|
+
*
|
|
1070
|
+
* For more control, you can use `app/router.options.ts` file.
|
|
1071
|
+
*
|
|
1072
|
+
* @see [documentation](https://kdujs-router.web.app/api/interfaces/routeroptions.html).
|
|
1073
|
+
* @type {import('../src/types/router').RouterConfigSerializable}
|
|
1074
|
+
*
|
|
1075
|
+
*/
|
|
339
1076
|
options: {}
|
|
340
1077
|
}
|
|
341
1078
|
});
|
|
342
1079
|
|
|
343
1080
|
const typescript = defineUntypedSchema({
|
|
1081
|
+
/**
|
|
1082
|
+
* Configuration for Dtwo's TypeScript integration.
|
|
1083
|
+
*
|
|
1084
|
+
*/
|
|
344
1085
|
typescript: {
|
|
1086
|
+
/**
|
|
1087
|
+
* TypeScript comes with certain checks to give you more safety and analysis of your program.
|
|
1088
|
+
* Once you’ve converted your codebase to TypeScript, you can start enabling these checks for greater safety.
|
|
1089
|
+
* [Read More](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html#getting-stricter-checks)
|
|
1090
|
+
*/
|
|
345
1091
|
strict: true,
|
|
1092
|
+
/**
|
|
1093
|
+
* Include parent workspace in the Dtwo project. Mostly useful for themes and module authors.
|
|
1094
|
+
*/
|
|
346
1095
|
includeWorkspace: false,
|
|
1096
|
+
/**
|
|
1097
|
+
* Enable build-time type checking.
|
|
1098
|
+
*
|
|
1099
|
+
* If set to true, this will type check in development. You can restrict this to build-time type checking by setting it to `build`.
|
|
1100
|
+
* Requires to install `typescript` and `kdu-tsc` as dev dependencies.
|
|
1101
|
+
*
|
|
1102
|
+
* @see https://dtwojs.web.app/docs/guide/concepts/typescript
|
|
1103
|
+
*
|
|
1104
|
+
* @type {boolean | 'build'}
|
|
1105
|
+
*/
|
|
347
1106
|
typeCheck: false,
|
|
1107
|
+
/**
|
|
1108
|
+
* You can extend generated `.dtwo/tsconfig.json` using this option.
|
|
1109
|
+
* @type {typeof import('pkg-types')['readPackageJSON']}
|
|
1110
|
+
*/
|
|
348
1111
|
tsConfig: {},
|
|
1112
|
+
/**
|
|
1113
|
+
* Generate a `*.kdu` shim.
|
|
1114
|
+
*
|
|
1115
|
+
* We recommend instead either enabling [**Take Over Mode**](https://kdu-js.web.app/guide/typescript/overview.html#kocan-takeover-mode) or adding
|
|
1116
|
+
* TypeScript Kdu Plugin (Kocan)** 👉 [[Download](https://marketplace.visualstudio.com/items?itemName=Kdu-Code.vscode-typescript-kdu-plugin)].
|
|
1117
|
+
*/
|
|
349
1118
|
shim: true
|
|
350
1119
|
}
|
|
351
1120
|
});
|
|
352
1121
|
|
|
353
1122
|
const wite = defineUntypedSchema({
|
|
1123
|
+
/**
|
|
1124
|
+
* Configuration that will be passed directly to Wite.
|
|
1125
|
+
*
|
|
1126
|
+
* See https://witejs.web.app/config for more information.
|
|
1127
|
+
* Please note that not all wite options are supported in Dtwo.
|
|
1128
|
+
*
|
|
1129
|
+
* @type {typeof import('../src/types/config').WiteConfig}
|
|
1130
|
+
*/
|
|
354
1131
|
wite: {
|
|
355
1132
|
root: {
|
|
356
1133
|
$resolve: async (val, get) => val ?? await get("srcDir")
|
|
@@ -358,7 +1135,9 @@ const wite = defineUntypedSchema({
|
|
|
358
1135
|
mode: {
|
|
359
1136
|
$resolve: async (val, get) => val ?? (await get("dev") ? "development" : "production")
|
|
360
1137
|
},
|
|
361
|
-
logLevel:
|
|
1138
|
+
logLevel: {
|
|
1139
|
+
$resolve: async (val, get) => val ?? (await get("dev") ? "warn" : "info")
|
|
1140
|
+
},
|
|
362
1141
|
define: {
|
|
363
1142
|
$resolve: async (val, get) => ({
|
|
364
1143
|
"process.dev": await get("dev"),
|
|
@@ -421,6 +1200,19 @@ const wite = defineUntypedSchema({
|
|
|
421
1200
|
|
|
422
1201
|
const webpack = defineUntypedSchema({
|
|
423
1202
|
webpack: {
|
|
1203
|
+
/**
|
|
1204
|
+
* Dtwo uses `webpack-bundle-analyzer` to visualize your bundles and how to optimize them.
|
|
1205
|
+
*
|
|
1206
|
+
* Set to `true` to enable bundle analysis, or pass an object with options: [for webpack](https://github.com/webpack-contrib/webpack-bundle-analyzer#options-for-plugin) or [for wite](https://github.com/btd/rollup-plugin-visualizer#options).
|
|
1207
|
+
*
|
|
1208
|
+
* @example
|
|
1209
|
+
* ```js
|
|
1210
|
+
* analyze: {
|
|
1211
|
+
* analyzerMode: 'static'
|
|
1212
|
+
* }
|
|
1213
|
+
* ```
|
|
1214
|
+
* @type {boolean | typeof import('webpack-bundle-analyzer').BundleAnalyzerPlugin.Options}
|
|
1215
|
+
*/
|
|
424
1216
|
analyze: {
|
|
425
1217
|
$resolve: async (val, get) => {
|
|
426
1218
|
if (val !== true) {
|
|
@@ -434,12 +1226,93 @@ const webpack = defineUntypedSchema({
|
|
|
434
1226
|
};
|
|
435
1227
|
}
|
|
436
1228
|
},
|
|
1229
|
+
/**
|
|
1230
|
+
* Enable the profiler in webpackbar.
|
|
1231
|
+
*
|
|
1232
|
+
* It is normally enabled by CLI argument `--profile`.
|
|
1233
|
+
*
|
|
1234
|
+
* @see [webpackbar](https://github.com/unjs/webpackbar#profile).
|
|
1235
|
+
*/
|
|
437
1236
|
profile: process.argv.includes("--profile"),
|
|
1237
|
+
/**
|
|
1238
|
+
* Enables Common CSS Extraction using
|
|
1239
|
+
* [Kdu Server Renderer guidelines](https://kdujs-ssr.web.app/guide/css.html).
|
|
1240
|
+
*
|
|
1241
|
+
* Using [extract-css-chunks-webpack-plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/) under the hood, your CSS will be extracted
|
|
1242
|
+
* into separate files, usually one per component. This allows caching your CSS and
|
|
1243
|
+
* JavaScript separately and is worth trying if you have a lot of global or shared CSS.
|
|
1244
|
+
*
|
|
1245
|
+
* @example
|
|
1246
|
+
* ```js
|
|
1247
|
+
* export default {
|
|
1248
|
+
* webpack: {
|
|
1249
|
+
* extractCSS: true,
|
|
1250
|
+
* // or
|
|
1251
|
+
* extractCSS: {
|
|
1252
|
+
* ignoreOrder: true
|
|
1253
|
+
* }
|
|
1254
|
+
* }
|
|
1255
|
+
* }
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* If you want to extract all your CSS to a single file, there is a workaround for this.
|
|
1259
|
+
* However, note that it is not recommended to extract everything into a single file.
|
|
1260
|
+
* Extracting into multiple CSS files is better for caching and preload isolation. It
|
|
1261
|
+
* can also improve page performance by downloading and resolving only those resources
|
|
1262
|
+
* that are needed.
|
|
1263
|
+
*
|
|
1264
|
+
* @example
|
|
1265
|
+
* ```js
|
|
1266
|
+
* export default {
|
|
1267
|
+
* webpack: {
|
|
1268
|
+
* extractCSS: true,
|
|
1269
|
+
* optimization: {
|
|
1270
|
+
* splitChunks: {
|
|
1271
|
+
* cacheGroups: {
|
|
1272
|
+
* styles: {
|
|
1273
|
+
* name: 'styles',
|
|
1274
|
+
* test: /\.(css|kdu)$/,
|
|
1275
|
+
* chunks: 'all',
|
|
1276
|
+
* enforce: true
|
|
1277
|
+
* }
|
|
1278
|
+
* }
|
|
1279
|
+
* }
|
|
1280
|
+
* }
|
|
1281
|
+
* }
|
|
1282
|
+
* }
|
|
1283
|
+
* ```
|
|
1284
|
+
* @type {boolean | typeof import('mini-css-extract-plugin').PluginOptions}
|
|
1285
|
+
*/
|
|
438
1286
|
extractCSS: true,
|
|
1287
|
+
/**
|
|
1288
|
+
* Enables CSS source map support (defaults to `true` in development).
|
|
1289
|
+
*/
|
|
439
1290
|
cssSourceMap: {
|
|
440
1291
|
$resolve: async (val, get) => val ?? await get("dev")
|
|
441
1292
|
},
|
|
1293
|
+
/**
|
|
1294
|
+
* The polyfill library to load to provide URL and URLSearchParams.
|
|
1295
|
+
*
|
|
1296
|
+
* Defaults to `'url'` ([see package](https://www.npmjs.com/package/url)).
|
|
1297
|
+
*/
|
|
442
1298
|
serverURLPolyfill: "url",
|
|
1299
|
+
/**
|
|
1300
|
+
* Customize bundle filenames.
|
|
1301
|
+
*
|
|
1302
|
+
* To understand a bit more about the use of manifests, take a look at [this webpack documentation](https://webpack.js.org/guides/code-splitting/).
|
|
1303
|
+
*
|
|
1304
|
+
* @note Be careful when using non-hashed based filenames in production
|
|
1305
|
+
* as most browsers will cache the asset and not detect the changes on first load.
|
|
1306
|
+
*
|
|
1307
|
+
* This example changes fancy chunk names to numerical ids:
|
|
1308
|
+
*
|
|
1309
|
+
* @example
|
|
1310
|
+
* ```js
|
|
1311
|
+
* filenames: {
|
|
1312
|
+
* chunk: ({ isDev }) => (isDev ? '[name].js' : '[id].[contenthash].js')
|
|
1313
|
+
* }
|
|
1314
|
+
* ```
|
|
1315
|
+
*/
|
|
443
1316
|
filenames: {
|
|
444
1317
|
app: ({ isDev }) => isDev ? `[name].js` : `[contenthash:7].js`,
|
|
445
1318
|
chunk: ({ isDev }) => isDev ? `[name].js` : `[contenthash:7].js`,
|
|
@@ -448,6 +1321,9 @@ const webpack = defineUntypedSchema({
|
|
|
448
1321
|
font: ({ isDev }) => isDev ? "[path][name].[ext]" : "fonts/[name].[contenthash:7].[ext]",
|
|
449
1322
|
video: ({ isDev }) => isDev ? "[path][name].[ext]" : "videos/[name].[contenthash:7].[ext]"
|
|
450
1323
|
},
|
|
1324
|
+
/**
|
|
1325
|
+
* Customize the options of Dtwo's integrated webpack loaders.
|
|
1326
|
+
*/
|
|
451
1327
|
loaders: {
|
|
452
1328
|
$resolve: async (val, get) => {
|
|
453
1329
|
const styleLoaders = [
|
|
@@ -508,15 +1384,60 @@ const webpack = defineUntypedSchema({
|
|
|
508
1384
|
stylus: {},
|
|
509
1385
|
kduStyle: {}
|
|
510
1386
|
},
|
|
1387
|
+
/**
|
|
1388
|
+
* Add webpack plugins.
|
|
1389
|
+
*
|
|
1390
|
+
* @example
|
|
1391
|
+
* ```js
|
|
1392
|
+
* import webpack from 'webpack'
|
|
1393
|
+
* import { version } from './package.json'
|
|
1394
|
+
* // ...
|
|
1395
|
+
* plugins: [
|
|
1396
|
+
* new webpack.DefinePlugin({
|
|
1397
|
+
* 'process.VERSION': version
|
|
1398
|
+
* })
|
|
1399
|
+
* ]
|
|
1400
|
+
* ```
|
|
1401
|
+
*/
|
|
511
1402
|
plugins: [],
|
|
1403
|
+
/**
|
|
1404
|
+
* Terser plugin options.
|
|
1405
|
+
*
|
|
1406
|
+
* Set to false to disable this plugin, or pass an object of options.
|
|
1407
|
+
*
|
|
1408
|
+
* @see [terser-webpack-plugin documentation](https://github.com/webpack-contrib/terser-webpack-plugin).
|
|
1409
|
+
*
|
|
1410
|
+
* @note Enabling sourceMap will leave `//# sourceMappingURL` linking comment at
|
|
1411
|
+
* the end of each output file if webpack `config.devtool` is set to `source-map`.
|
|
1412
|
+
*
|
|
1413
|
+
* @type {false | typeof import('terser-webpack-plugin').BasePluginOptions & typeof import('terser-webpack-plugin').DefinedDefaultMinimizerAndOptions<any>}
|
|
1414
|
+
*/
|
|
512
1415
|
terser: {},
|
|
1416
|
+
/**
|
|
1417
|
+
* Hard-replaces `typeof process`, `typeof window` and `typeof document` to tree-shake bundle.
|
|
1418
|
+
*/
|
|
513
1419
|
aggressiveCodeRemoval: false,
|
|
1420
|
+
/**
|
|
1421
|
+
* OptimizeCSSAssets plugin options.
|
|
1422
|
+
*
|
|
1423
|
+
* Defaults to true when `extractCSS` is enabled.
|
|
1424
|
+
*
|
|
1425
|
+
* @see [css-minimizer-webpack-plugin documentation](https://github.com/webpack-contrib/css-minimizer-webpack-plugin).
|
|
1426
|
+
*
|
|
1427
|
+
* @type {false | typeof import('css-minimizer-webpack-plugin').BasePluginOptions & typeof import('css-minimizer-webpack-plugin').DefinedDefaultMinimizerAndOptions<any>}
|
|
1428
|
+
*/
|
|
514
1429
|
optimizeCSS: {
|
|
515
1430
|
$resolve: async (val, get) => val ?? (await get("build.extractCSS") ? {} : false)
|
|
516
1431
|
},
|
|
1432
|
+
/**
|
|
1433
|
+
* Configure [webpack optimization](https://webpack.js.org/configuration/optimization/).
|
|
1434
|
+
* @type {false | typeof import('webpack').Configuration['optimization']}
|
|
1435
|
+
*/
|
|
517
1436
|
optimization: {
|
|
518
1437
|
runtimeChunk: "single",
|
|
1438
|
+
/** Set minimize to `false` to disable all minimizers. (It is disabled in development by default). */
|
|
519
1439
|
minimize: { $resolve: async (val, get) => val ?? !await get("dev") },
|
|
1440
|
+
/** You can set minimizer to a customized array of plugins. */
|
|
520
1441
|
minimizer: void 0,
|
|
521
1442
|
splitChunks: {
|
|
522
1443
|
chunks: "all",
|
|
@@ -524,6 +1445,10 @@ const webpack = defineUntypedSchema({
|
|
|
524
1445
|
cacheGroups: {}
|
|
525
1446
|
}
|
|
526
1447
|
},
|
|
1448
|
+
/**
|
|
1449
|
+
* Customize PostCSS Loader.
|
|
1450
|
+
* Same options as https://github.com/webpack-contrib/postcss-loader#options
|
|
1451
|
+
*/
|
|
527
1452
|
postcss: {
|
|
528
1453
|
execute: void 0,
|
|
529
1454
|
postcssOptions: {
|
|
@@ -538,11 +1463,26 @@ const webpack = defineUntypedSchema({
|
|
|
538
1463
|
implementation: void 0,
|
|
539
1464
|
order: ""
|
|
540
1465
|
},
|
|
1466
|
+
/**
|
|
1467
|
+
* See [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) for available options.
|
|
1468
|
+
* @type {typeof import('webpack-dev-middleware').Options<typeof import('http').IncomingMessage, typeof import('http').ServerResponse>}
|
|
1469
|
+
*/
|
|
541
1470
|
devMiddleware: {
|
|
542
1471
|
stats: "none"
|
|
543
1472
|
},
|
|
1473
|
+
/**
|
|
1474
|
+
* See [webpack-hot-middleware](https://github.com/webpack-contrib/webpack-hot-middleware) for available options.
|
|
1475
|
+
* @type {typeof import('webpack-hot-middleware').MiddlewareOptions & { client?: typeof import('webpack-hot-middleware').ClientOptions }}
|
|
1476
|
+
*/
|
|
544
1477
|
hotMiddleware: {},
|
|
1478
|
+
/**
|
|
1479
|
+
* Set to `false` to disable the overlay provided by [FriendlyErrorsWebpackPlugin](https://www.npmjs.com/package/@d2js/friendly-errors-webpack-plugin).
|
|
1480
|
+
*/
|
|
545
1481
|
friendlyErrors: true,
|
|
1482
|
+
/**
|
|
1483
|
+
* Filters to hide build warnings.
|
|
1484
|
+
* @type {Array<(warn: typeof import('webpack').WebpackError) => boolean>}
|
|
1485
|
+
*/
|
|
546
1486
|
warningIgnoreFilters: []
|
|
547
1487
|
}
|
|
548
1488
|
});
|