vitrify 0.3.0 → 0.5.1
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/README.md +2 -2
- package/dist/app-urls.js +1 -1
- package/dist/bin/build.js +9 -8
- package/dist/bin/cli.js +28 -6
- package/dist/bin/dev.js +73 -29
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -18
- package/dist/frameworks/vue/server.js +10 -5
- package/dist/helpers/collect-css-ssr.js +61 -0
- package/dist/index.js +298 -77
- package/dist/plugins/quasar.js +30 -9
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +43 -4
- package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/server.d.ts +10 -5
- package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
- package/dist/types/helpers/routes.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/vitrify-config.d.ts +16 -5
- package/package.json +33 -32
- package/src/node/app-urls.ts +1 -1
- package/src/node/bin/build.ts +11 -10
- package/src/node/bin/cli.ts +35 -7
- package/src/node/bin/dev.ts +109 -38
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -20
- package/src/node/frameworks/vue/server.ts +24 -9
- package/src/node/helpers/collect-css-ssr.ts +85 -0
- package/src/node/index.ts +338 -90
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +40 -9
- package/src/node/vitrify-config.ts +20 -5
- package/src/vite/fastify/entry.ts +11 -0
- package/src/vite/fastify/server.ts +12 -0
- package/src/vite/vue/csr/app.ts +25 -0
- package/src/vite/vue/csr/fastify-csr-plugin.ts +3 -0
- package/src/vite/vue/csr/server.ts +8 -0
- package/src/vite/vue/index.html +1 -0
- package/src/vite/vue/main.ts +0 -1
- package/src/vite/vue/ssr/app.ts +25 -0
- package/src/vite/vue/ssr/entry-server.ts +13 -1
- package/src/vite/vue/ssr/server.ts +23 -14
package/src/node/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue'
|
|
2
|
-
import type { InlineConfig, UserConfig } from 'vite'
|
|
2
|
+
import type { Alias, InlineConfig, UserConfig } from 'vite'
|
|
3
|
+
import { resolveConfig } from 'vite'
|
|
3
4
|
import { mergeConfig } from 'vite'
|
|
5
|
+
import { build } from 'esbuild'
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
import { pathToFileURL } from 'url'
|
|
4
9
|
import { readFileSync } from 'fs'
|
|
5
10
|
import builtinModules from 'builtin-modules'
|
|
6
11
|
import { resolve } from 'import-meta-resolve'
|
|
@@ -11,20 +16,65 @@ import type {
|
|
|
11
16
|
VitrifyConfig,
|
|
12
17
|
OnRenderedHook,
|
|
13
18
|
OnBootHook,
|
|
14
|
-
|
|
19
|
+
OnSetupFile
|
|
15
20
|
} from './vitrify-config.js'
|
|
16
21
|
import type { VitrifyContext } from './bin/run.js'
|
|
17
22
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
18
23
|
import { getPkgJsonDir } from './app-urls.js'
|
|
24
|
+
import type { RollupOptions } from 'rollup'
|
|
19
25
|
|
|
20
|
-
const
|
|
26
|
+
const internalServerModules = [
|
|
27
|
+
// 'fs',
|
|
28
|
+
// 'path',
|
|
29
|
+
// 'url',
|
|
30
|
+
// 'module',
|
|
31
|
+
// 'crypto',
|
|
32
|
+
// 'node:fs',
|
|
33
|
+
'util',
|
|
34
|
+
'node:url',
|
|
35
|
+
'node:util',
|
|
36
|
+
'node:fs',
|
|
37
|
+
'node:process',
|
|
38
|
+
'vitrify',
|
|
39
|
+
'vitrify/dev',
|
|
40
|
+
// 'import-meta-resolve',
|
|
41
|
+
'vite',
|
|
42
|
+
'fastify',
|
|
43
|
+
'@fastify',
|
|
44
|
+
'node'
|
|
45
|
+
// 'middie',
|
|
46
|
+
// 'knex',
|
|
47
|
+
// 'bcrypt',
|
|
48
|
+
// 'objection',
|
|
49
|
+
// '@fastify/formbody',
|
|
50
|
+
// '@fastify/static',
|
|
51
|
+
// '@fastify/cors',
|
|
52
|
+
// '@fastify/cookie',
|
|
53
|
+
// 'mercurius',
|
|
54
|
+
// 'jose',
|
|
55
|
+
// 'oidc-provider',
|
|
56
|
+
// 'node-fetch'
|
|
57
|
+
]
|
|
21
58
|
|
|
22
59
|
const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
|
|
23
60
|
quasar: () =>
|
|
24
61
|
import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
25
62
|
}
|
|
26
63
|
|
|
27
|
-
const
|
|
64
|
+
const manualChunkNames = [
|
|
65
|
+
'prerender',
|
|
66
|
+
'fastify-ssr-plugin',
|
|
67
|
+
'fastify-csr-plugin',
|
|
68
|
+
'server'
|
|
69
|
+
]
|
|
70
|
+
const manualChunks = (id: string) => {
|
|
71
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
72
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
73
|
+
if (name && manualChunkNames.includes(name)) return name
|
|
74
|
+
} else if (id.includes('node_modules')) {
|
|
75
|
+
return 'vendor'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
28
78
|
|
|
29
79
|
export const VIRTUAL_MODULES = [
|
|
30
80
|
'virtual:vitrify-hooks',
|
|
@@ -32,18 +82,78 @@ export const VIRTUAL_MODULES = [
|
|
|
32
82
|
'virtual:static-imports'
|
|
33
83
|
]
|
|
34
84
|
|
|
85
|
+
async function bundleConfigFile(
|
|
86
|
+
fileName: string,
|
|
87
|
+
isESM = false
|
|
88
|
+
): Promise<{ code: string; dependencies: string[] }> {
|
|
89
|
+
const result = await build({
|
|
90
|
+
absWorkingDir: process.cwd(),
|
|
91
|
+
entryPoints: [fileName],
|
|
92
|
+
outfile: 'out.js',
|
|
93
|
+
write: false,
|
|
94
|
+
platform: 'node',
|
|
95
|
+
bundle: true,
|
|
96
|
+
format: 'esm',
|
|
97
|
+
sourcemap: 'inline',
|
|
98
|
+
metafile: true,
|
|
99
|
+
plugins: [
|
|
100
|
+
{
|
|
101
|
+
name: 'externalize-deps',
|
|
102
|
+
setup(build) {
|
|
103
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
104
|
+
const id = args.path
|
|
105
|
+
if (id[0] !== '.' && !path.isAbsolute(id)) {
|
|
106
|
+
return {
|
|
107
|
+
external: true
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'replace-import-meta',
|
|
115
|
+
setup(build) {
|
|
116
|
+
build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
|
|
117
|
+
const contents = await fs.promises.readFile(args.path, 'utf8')
|
|
118
|
+
return {
|
|
119
|
+
loader: args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
120
|
+
contents: contents
|
|
121
|
+
.replace(
|
|
122
|
+
/\bimport\.meta\.url\b/g,
|
|
123
|
+
JSON.stringify(pathToFileURL(args.path).href)
|
|
124
|
+
)
|
|
125
|
+
.replace(
|
|
126
|
+
/\b__dirname\b/g,
|
|
127
|
+
JSON.stringify(path.dirname(args.path))
|
|
128
|
+
)
|
|
129
|
+
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
const { text } = result.outputFiles[0]
|
|
137
|
+
return {
|
|
138
|
+
code: text,
|
|
139
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
35
143
|
export const baseConfig = async ({
|
|
36
144
|
ssr,
|
|
37
145
|
appDir,
|
|
38
146
|
publicDir,
|
|
147
|
+
base = '/',
|
|
39
148
|
command = 'build',
|
|
40
149
|
mode = 'production',
|
|
41
150
|
framework = 'vue',
|
|
42
151
|
pwa = false
|
|
43
152
|
}: {
|
|
44
|
-
ssr?: 'client' | 'server' | 'ssg'
|
|
153
|
+
ssr?: 'client' | 'server' | 'ssg' | 'fastify'
|
|
45
154
|
appDir?: URL
|
|
46
155
|
publicDir?: URL
|
|
156
|
+
base?: string
|
|
47
157
|
command?: 'build' | 'dev' | 'test'
|
|
48
158
|
mode?: 'production' | 'development'
|
|
49
159
|
framework?: 'vue'
|
|
@@ -59,22 +169,7 @@ export const baseConfig = async ({
|
|
|
59
169
|
const cliDir = getCliDir()
|
|
60
170
|
const cliViteDir = getCliViteDir(cliDir)
|
|
61
171
|
const frameworkDir = new URL(`${framework}/`, cliViteDir)
|
|
62
|
-
|
|
63
|
-
const localPackages = ['vue', 'vue-router']
|
|
64
|
-
const cliPackages = ['vitest']
|
|
65
|
-
const packageUrls: Record<string, URL> = {}
|
|
66
|
-
await (async () => {
|
|
67
|
-
for (const val of localPackages)
|
|
68
|
-
packageUrls[val] = getPkgJsonDir(
|
|
69
|
-
new URL(await resolve(val, appDir!.href))
|
|
70
|
-
)
|
|
71
|
-
})()
|
|
72
|
-
await (async () => {
|
|
73
|
-
for (const val of cliPackages)
|
|
74
|
-
packageUrls[val] = getPkgJsonDir(
|
|
75
|
-
new URL(await resolve(val, cliDir!.href))
|
|
76
|
-
)
|
|
77
|
-
})()
|
|
172
|
+
const fastifyDir = new URL('fastify/', cliViteDir)
|
|
78
173
|
|
|
79
174
|
if (!publicDir) publicDir = new URL('public/', appDir)
|
|
80
175
|
/**
|
|
@@ -82,24 +177,63 @@ export const baseConfig = async ({
|
|
|
82
177
|
*/
|
|
83
178
|
let vitrifyConfig:
|
|
84
179
|
| VitrifyConfig
|
|
85
|
-
| (({
|
|
180
|
+
| (({
|
|
181
|
+
mode,
|
|
182
|
+
command
|
|
183
|
+
}: {
|
|
184
|
+
mode: string
|
|
185
|
+
command: string
|
|
186
|
+
}) => Promise<VitrifyConfig> | VitrifyConfig)
|
|
86
187
|
|
|
87
188
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
189
|
+
if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
|
|
190
|
+
const configPath = new URL('vitrify.config.ts', appDir).pathname
|
|
191
|
+
const bundledConfig = await bundleConfigFile(
|
|
192
|
+
new URL('vitrify.config.ts', appDir).pathname
|
|
193
|
+
)
|
|
194
|
+
fs.writeFileSync(configPath + '.js', bundledConfig.code)
|
|
195
|
+
vitrifyConfig = (await import(configPath + '.js')).default
|
|
196
|
+
fs.unlinkSync(configPath + '.js')
|
|
197
|
+
} else {
|
|
198
|
+
vitrifyConfig = (
|
|
199
|
+
await import(new URL('vitrify.config.js', appDir).pathname)
|
|
200
|
+
).default
|
|
201
|
+
}
|
|
91
202
|
if (typeof vitrifyConfig === 'function')
|
|
92
|
-
vitrifyConfig = vitrifyConfig({ mode, command })
|
|
203
|
+
vitrifyConfig = await vitrifyConfig({ mode, command })
|
|
93
204
|
} catch (e) {
|
|
94
|
-
console.
|
|
95
|
-
console.log('No vitrify.config.js file found, using defaults')
|
|
205
|
+
console.log('No vitrify.config.(ts|js) file found, using defaults')
|
|
96
206
|
vitrifyConfig = {}
|
|
97
207
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
208
|
+
|
|
209
|
+
const localPackages = ['vue', 'vue-router']
|
|
210
|
+
const cliPackages = []
|
|
211
|
+
const packageUrls: Record<string, URL> =
|
|
212
|
+
vitrifyConfig.vitrify?.urls?.packages || {}
|
|
213
|
+
await (async () => {
|
|
214
|
+
for (const val of localPackages)
|
|
215
|
+
packageUrls[val] = getPkgJsonDir(
|
|
216
|
+
new URL(await resolve(val, appDir!.href))
|
|
217
|
+
)
|
|
218
|
+
})()
|
|
219
|
+
|
|
220
|
+
// await (async () => {
|
|
221
|
+
// for (const val of cliPackages)
|
|
222
|
+
// packageUrls[val] = getPkgJsonDir(
|
|
223
|
+
// new URL(await resolve(val, cliDir!.href))
|
|
224
|
+
// )
|
|
225
|
+
// })()
|
|
226
|
+
|
|
227
|
+
let productName = 'Product name'
|
|
228
|
+
try {
|
|
229
|
+
;({ productName } = JSON.parse(
|
|
230
|
+
readFileSync(new URL('package.json', appDir).pathname, {
|
|
231
|
+
encoding: 'utf-8'
|
|
232
|
+
})
|
|
233
|
+
))
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.error('package.json not found')
|
|
236
|
+
}
|
|
103
237
|
|
|
104
238
|
const ssrTransformCustomDir = () => {
|
|
105
239
|
return {
|
|
@@ -124,14 +258,22 @@ export const baseConfig = async ({
|
|
|
124
258
|
let onBootHooks: OnBootHook[]
|
|
125
259
|
let onRenderedHooks: OnRenderedHook[]
|
|
126
260
|
let onMountedHooks: OnMountedHook[]
|
|
127
|
-
let
|
|
261
|
+
let onSetupFiles: OnSetupFile[]
|
|
128
262
|
let globalCss: string[]
|
|
129
263
|
let staticImports: StaticImports
|
|
130
264
|
let sassVariables: Record<string, string>
|
|
131
265
|
let additionalData: string[]
|
|
266
|
+
let serverModules: string[] = internalServerModules
|
|
267
|
+
|
|
268
|
+
if (vitrifyConfig.vitrify?.ssr?.serverModules)
|
|
269
|
+
serverModules = [
|
|
270
|
+
...serverModules,
|
|
271
|
+
...vitrifyConfig.vitrify.ssr.serverModules
|
|
272
|
+
]
|
|
132
273
|
|
|
133
274
|
const plugins: UserConfig['plugins'] = [
|
|
134
275
|
vuePlugin({
|
|
276
|
+
compiler: await import('vue/compiler-sfc'),
|
|
135
277
|
template: {
|
|
136
278
|
ssr: !!ssr,
|
|
137
279
|
compilerOptions: {
|
|
@@ -159,7 +301,7 @@ export const baseConfig = async ({
|
|
|
159
301
|
onBootHooks = config.vitrify?.hooks?.onBoot || []
|
|
160
302
|
onRenderedHooks = config.vitrify?.hooks?.onRendered || []
|
|
161
303
|
onMountedHooks = config.vitrify?.hooks?.onMounted || []
|
|
162
|
-
|
|
304
|
+
onSetupFiles = config?.vitrify?.hooks?.onSetup || []
|
|
163
305
|
globalCss = config.vitrify?.globalCss || []
|
|
164
306
|
staticImports = config.vitrify?.staticImports || {}
|
|
165
307
|
sassVariables = config.vitrify?.sass?.variables || {}
|
|
@@ -188,9 +330,17 @@ export const baseConfig = async ({
|
|
|
188
330
|
}
|
|
189
331
|
},
|
|
190
332
|
resolveId(id) {
|
|
191
|
-
if (VIRTUAL_MODULES.includes(id))
|
|
333
|
+
if (VIRTUAL_MODULES.includes(id))
|
|
334
|
+
return { id, moduleSideEffects: false }
|
|
192
335
|
return
|
|
193
336
|
},
|
|
337
|
+
transform: (code, id) => {
|
|
338
|
+
if (id.endsWith('main.ts') && id.includes('vitrify')) {
|
|
339
|
+
code =
|
|
340
|
+
`${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
|
|
341
|
+
}
|
|
342
|
+
return code
|
|
343
|
+
},
|
|
194
344
|
load(id) {
|
|
195
345
|
if (id === 'virtual:vitrify-hooks') {
|
|
196
346
|
return `export const onBoot = [${onBootHooks
|
|
@@ -202,11 +352,27 @@ export const baseConfig = async ({
|
|
|
202
352
|
export const onRendered = [${onRenderedHooks
|
|
203
353
|
.map((fn) => `${String(fn)}`)
|
|
204
354
|
.join(', ')}]
|
|
205
|
-
export const onSetup = [
|
|
206
|
-
|
|
207
|
-
.
|
|
208
|
-
|
|
209
|
-
|
|
355
|
+
export const onSetup = []
|
|
356
|
+
${onSetupFiles
|
|
357
|
+
.map(
|
|
358
|
+
(url, index) =>
|
|
359
|
+
`import ${url.pathname
|
|
360
|
+
.replaceAll('/', '')
|
|
361
|
+
.replaceAll('.', '')} from '${
|
|
362
|
+
url.pathname
|
|
363
|
+
}'; onSetup.push(${url.pathname
|
|
364
|
+
.replaceAll('/', '')
|
|
365
|
+
.replaceAll('.', '')})`
|
|
366
|
+
)
|
|
367
|
+
.join('\n')}`
|
|
368
|
+
// export const onSetup = [${onSetupHooks
|
|
369
|
+
// .map((fn) => `${String(fn)}`)
|
|
370
|
+
// .join(', ')}]`
|
|
371
|
+
/**
|
|
372
|
+
* CSS imports in virtual files do not seem to work. Using transform() instead
|
|
373
|
+
*/
|
|
374
|
+
// } else if (id === 'virtual:global-css') {
|
|
375
|
+
// return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
|
|
210
376
|
} else if (id === 'virtual:static-imports') {
|
|
211
377
|
return `${Object.entries(staticImports)
|
|
212
378
|
.map(
|
|
@@ -242,6 +408,9 @@ export const baseConfig = async ({
|
|
|
242
408
|
case 'client':
|
|
243
409
|
entry = new URL('ssr/entry-client.ts', frameworkDir).pathname
|
|
244
410
|
break
|
|
411
|
+
case 'fastify':
|
|
412
|
+
entry = new URL('entry.ts', fastifyDir).pathname
|
|
413
|
+
break
|
|
245
414
|
default:
|
|
246
415
|
entry = new URL('csr/entry.ts', frameworkDir).pathname
|
|
247
416
|
}
|
|
@@ -271,25 +440,110 @@ export const baseConfig = async ({
|
|
|
271
440
|
})
|
|
272
441
|
}
|
|
273
442
|
|
|
274
|
-
const alias = [
|
|
443
|
+
const alias: Alias[] = [
|
|
275
444
|
{ find: 'src', replacement: srcDir.pathname },
|
|
276
445
|
{ find: 'app', replacement: appDir.pathname },
|
|
277
446
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
278
447
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
279
448
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
449
|
+
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
450
|
+
find: key,
|
|
451
|
+
replacement: value.pathname
|
|
452
|
+
}))
|
|
453
|
+
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
454
|
+
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
455
|
+
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
283
456
|
]
|
|
457
|
+
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
458
|
+
alias.push(...vitrifyConfig.vitrify.dev.alias)
|
|
459
|
+
|
|
284
460
|
if (command === 'test')
|
|
285
461
|
alias.push({
|
|
286
462
|
find: 'vitest',
|
|
287
|
-
replacement:
|
|
463
|
+
replacement: new URL(await resolve('vitest', cliDir!.href)).pathname
|
|
288
464
|
})
|
|
289
465
|
|
|
466
|
+
let rollupOptions: RollupOptions = {}
|
|
467
|
+
let noExternal: RegExp[] | string[] = [
|
|
468
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
469
|
+
]
|
|
470
|
+
const external = [...builtinModules, ...serverModules]
|
|
471
|
+
|
|
472
|
+
if (ssr === 'server') {
|
|
473
|
+
rollupOptions = {
|
|
474
|
+
input: [
|
|
475
|
+
new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
476
|
+
new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
477
|
+
new URL('ssr/server.ts', frameworkDir).pathname
|
|
478
|
+
],
|
|
479
|
+
external,
|
|
480
|
+
output: {
|
|
481
|
+
minifyInternalExports: false,
|
|
482
|
+
entryFileNames: '[name].mjs',
|
|
483
|
+
chunkFileNames: '[name].mjs',
|
|
484
|
+
format: 'es',
|
|
485
|
+
manualChunks
|
|
486
|
+
// manualChunks: (id) => {
|
|
487
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
488
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
489
|
+
// if (name && manualChunks.includes(name)) return name
|
|
490
|
+
// } else if (id.includes('node_modules')) {
|
|
491
|
+
// return 'vendor'
|
|
492
|
+
// }
|
|
493
|
+
// }
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
// Create a SSR bundle
|
|
497
|
+
noExternal = [
|
|
498
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
499
|
+
// new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
500
|
+
]
|
|
501
|
+
} else if (ssr === 'fastify') {
|
|
502
|
+
rollupOptions = {
|
|
503
|
+
input: [new URL('server.ts', fastifyDir).pathname],
|
|
504
|
+
external,
|
|
505
|
+
output: {
|
|
506
|
+
minifyInternalExports: false,
|
|
507
|
+
entryFileNames: '[name].mjs',
|
|
508
|
+
chunkFileNames: '[name].mjs',
|
|
509
|
+
format: 'es',
|
|
510
|
+
manualChunks
|
|
511
|
+
// manualChunks: (id) => {
|
|
512
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
513
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
514
|
+
// if (name && manualChunks.includes(name)) return name
|
|
515
|
+
// } else if (id.includes('node_modules')) {
|
|
516
|
+
// return 'vendor'
|
|
517
|
+
// }
|
|
518
|
+
// }
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
// Create a SSR bundle
|
|
522
|
+
noExternal = [
|
|
523
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
524
|
+
]
|
|
525
|
+
} else {
|
|
526
|
+
rollupOptions = {
|
|
527
|
+
input: [
|
|
528
|
+
new URL('index.html', frameworkDir).pathname
|
|
529
|
+
// new URL('csr/server.ts', frameworkDir).pathname
|
|
530
|
+
],
|
|
531
|
+
external,
|
|
532
|
+
output: {
|
|
533
|
+
minifyInternalExports: false,
|
|
534
|
+
entryFileNames: '[name].mjs',
|
|
535
|
+
chunkFileNames: '[name].mjs',
|
|
536
|
+
format: 'es',
|
|
537
|
+
manualChunks
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
290
542
|
const config = {
|
|
291
|
-
root: frameworkDir.pathname,
|
|
543
|
+
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
292
544
|
publicDir: publicDir.pathname,
|
|
545
|
+
base,
|
|
546
|
+
envDir: appDir.pathname,
|
|
293
547
|
vitrify: {
|
|
294
548
|
productName,
|
|
295
549
|
urls: {
|
|
@@ -302,64 +556,58 @@ export const baseConfig = async ({
|
|
|
302
556
|
},
|
|
303
557
|
plugins,
|
|
304
558
|
optimizeDeps: {
|
|
305
|
-
exclude: ['vue']
|
|
559
|
+
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
306
560
|
},
|
|
307
561
|
resolve: {
|
|
308
|
-
|
|
309
|
-
// dedupe: [
|
|
310
|
-
// 'vue',
|
|
311
|
-
// 'vue-router'
|
|
312
|
-
// ],
|
|
562
|
+
dedupe: ['vue', 'vue-router'],
|
|
313
563
|
alias
|
|
314
564
|
},
|
|
315
565
|
build: {
|
|
316
|
-
target: ssr === 'server' ? 'esnext' : 'modules',
|
|
317
|
-
ssr: ssr === 'server' ? true : false,
|
|
566
|
+
target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
|
|
567
|
+
ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
|
|
318
568
|
ssrManifest: ssr === 'client' || ssr === 'ssg',
|
|
319
|
-
rollupOptions
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
569
|
+
rollupOptions
|
|
570
|
+
// ssr === 'server'
|
|
571
|
+
// ? {
|
|
572
|
+
// input: [
|
|
573
|
+
// new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
574
|
+
// new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
575
|
+
// new URL('ssr/server.ts', frameworkDir).pathname
|
|
576
|
+
// ],
|
|
577
|
+
// output: {
|
|
578
|
+
// minifyInternalExports: false,
|
|
579
|
+
// entryFileNames: '[name].mjs',
|
|
580
|
+
// chunkFileNames: '[name].mjs',
|
|
581
|
+
// format: 'es',
|
|
582
|
+
// manualChunks: (id) => {
|
|
583
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
584
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
585
|
+
// if (name && manualChunks.includes(name)) return name
|
|
586
|
+
// } else if (id.includes('node_modules')) {
|
|
587
|
+
// return 'vendor'
|
|
588
|
+
// }
|
|
589
|
+
// }
|
|
590
|
+
// }
|
|
591
|
+
// }
|
|
592
|
+
// : {
|
|
593
|
+
// output: {
|
|
594
|
+
// format: 'es'
|
|
595
|
+
// }
|
|
596
|
+
// }
|
|
348
597
|
},
|
|
349
598
|
ssr: {
|
|
350
599
|
// Create a SSR bundle
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`
|
|
354
|
-
)
|
|
355
|
-
]
|
|
600
|
+
external,
|
|
601
|
+
noExternal
|
|
356
602
|
},
|
|
357
603
|
define: {
|
|
358
|
-
__BASE_URL__: `'
|
|
604
|
+
__BASE_URL__: `'${base}'`
|
|
359
605
|
}
|
|
360
606
|
} as VitrifyConfig
|
|
361
607
|
|
|
362
608
|
return mergeConfig(config, vitrifyConfig)
|
|
363
609
|
}
|
|
364
610
|
|
|
611
|
+
export const vitrifyDir = new URL('..', import.meta.url)
|
|
612
|
+
|
|
365
613
|
export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction }
|
|
@@ -85,6 +85,29 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
85
85
|
Components({
|
|
86
86
|
resolvers: [QuasarResolver()]
|
|
87
87
|
}),
|
|
88
|
+
{
|
|
89
|
+
name: 'vite-plugin-quasar-transform',
|
|
90
|
+
enforce: 'pre',
|
|
91
|
+
transform: (code, id, options) => {
|
|
92
|
+
const { ssr } = options || {}
|
|
93
|
+
code = code
|
|
94
|
+
.replaceAll('__QUASAR_SSR__', ssr ? ssr.toString() : 'false')
|
|
95
|
+
.replaceAll(
|
|
96
|
+
'__QUASAR_SSR_SERVER__',
|
|
97
|
+
ssr ? 'import.meta.env.SSR' : 'false'
|
|
98
|
+
)
|
|
99
|
+
.replaceAll(
|
|
100
|
+
'__QUASAR_SSR_CLIENT__',
|
|
101
|
+
ssr ? '!import.meta.env.SSR' : 'false'
|
|
102
|
+
)
|
|
103
|
+
.replaceAll(
|
|
104
|
+
'__QUASAR_SSR_PWA__',
|
|
105
|
+
ssr && pwa ? '!import.meta.env.SSR' : 'false'
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return code
|
|
109
|
+
}
|
|
110
|
+
},
|
|
88
111
|
{
|
|
89
112
|
name: 'vite-plugin-quasar-setup',
|
|
90
113
|
enforce: 'pre',
|
|
@@ -121,7 +144,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
121
144
|
const directives = await import('quasar/src/directives.js')
|
|
122
145
|
|
|
123
146
|
app.use(
|
|
124
|
-
staticImports
|
|
147
|
+
staticImports?.Quasar,
|
|
125
148
|
{
|
|
126
149
|
plugins: quasarPlugins,
|
|
127
150
|
directives
|
|
@@ -221,9 +244,14 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
221
244
|
replacement: new URL('src/', urls?.packages?.quasar).pathname
|
|
222
245
|
},
|
|
223
246
|
{
|
|
224
|
-
find: 'quasar',
|
|
225
|
-
replacement: new URL('src/', urls?.packages?.quasar)
|
|
247
|
+
find: new RegExp('^quasar$'),
|
|
248
|
+
replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
249
|
+
.pathname
|
|
226
250
|
},
|
|
251
|
+
// {
|
|
252
|
+
// find: 'quasar',
|
|
253
|
+
// replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
|
|
254
|
+
// },
|
|
227
255
|
{
|
|
228
256
|
find: `@quasar/extras`,
|
|
229
257
|
replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
@@ -233,11 +261,14 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
233
261
|
},
|
|
234
262
|
define: {
|
|
235
263
|
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
236
|
-
__QUASAR_VERSION__: `'${version}'
|
|
237
|
-
__QUASAR_SSR__: !!ssr,
|
|
238
|
-
__QUASAR_SSR_SERVER__: ssr === 'server',
|
|
239
|
-
|
|
240
|
-
|
|
264
|
+
__QUASAR_VERSION__: `'${version}'`
|
|
265
|
+
// __QUASAR_SSR__: !!ssr,
|
|
266
|
+
// // __QUASAR_SSR_SERVER__: ssr === 'server',
|
|
267
|
+
// __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
|
|
268
|
+
// // __QUASAR_SSR_CLIENT__: ssr === 'client',
|
|
269
|
+
// __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
|
|
270
|
+
// // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
|
|
271
|
+
// __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
|
|
241
272
|
},
|
|
242
273
|
ssr: {
|
|
243
274
|
noExternal: ['quasar']
|
|
@@ -251,7 +282,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
251
282
|
config: async (config, env) => ({
|
|
252
283
|
resolve: {
|
|
253
284
|
alias: [
|
|
254
|
-
{ find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
285
|
+
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
255
286
|
]
|
|
256
287
|
}
|
|
257
288
|
}),
|