vitrify 0.4.0 → 0.5.2
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/bin/build.js +10 -8
- package/dist/bin/cli.js +6 -4
- package/dist/bin/dev.js +36 -24
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +53 -39
- package/dist/frameworks/vue/server.js +2 -2
- package/dist/helpers/collect-css-ssr.js +6 -2
- package/dist/index.js +78 -57
- package/dist/plugins/quasar.js +22 -10
- package/dist/types/bin/build.d.ts +1 -0
- package/dist/types/bin/dev.d.ts +8 -5
- package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
- package/dist/types/frameworks/vue/server.d.ts +3 -2
- package/dist/types/helpers/collect-css-ssr.d.ts +5 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/vitrify-config.d.ts +13 -1
- package/package.json +6 -4
- package/src/node/bin/build.ts +11 -8
- package/src/node/bin/cli.ts +7 -4
- package/src/node/bin/dev.ts +41 -28
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +57 -40
- package/src/node/frameworks/vue/server.ts +4 -3
- package/src/node/helpers/collect-css-ssr.ts +12 -4
- package/src/node/index.ts +89 -56
- package/src/node/plugins/quasar.ts +33 -10
- package/src/node/vitrify-config.ts +13 -2
- package/src/vite/fastify/server.ts +3 -1
- 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/ssr/app.ts +1 -1
|
@@ -3,11 +3,12 @@ import type {
|
|
|
3
3
|
FastifyRequest,
|
|
4
4
|
FastifyReply
|
|
5
5
|
} from 'fastify'
|
|
6
|
-
import fastifyStatic from '@fastify/static'
|
|
6
|
+
import { fastifyStatic } from '@fastify/static'
|
|
7
7
|
import { readFileSync } from 'fs'
|
|
8
8
|
import type { OnRenderedHook } from '../../vitrify-config.js'
|
|
9
9
|
import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
|
|
10
10
|
import type { ViteDevServer } from 'vite'
|
|
11
|
+
|
|
11
12
|
export interface FastifySsrOptions {
|
|
12
13
|
baseUrl?: string
|
|
13
14
|
provide?: (
|
|
@@ -30,72 +31,86 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
30
31
|
done
|
|
31
32
|
) => {
|
|
32
33
|
options.vitrifyDir =
|
|
33
|
-
options.vitrifyDir ||
|
|
34
|
-
const frameworkDir = new URL('vite/vue/', options.vitrifyDir)
|
|
34
|
+
options.vitrifyDir || (await import('vitrify')).vitrifyDir
|
|
35
|
+
const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir)
|
|
35
36
|
options.baseUrl = options.baseUrl || '/'
|
|
37
|
+
options.mode = options.mode || process.env.MODE || import.meta.env.MODE
|
|
38
|
+
options.appDir = options.appDir || new URL('../../..', import.meta.url)
|
|
39
|
+
|
|
36
40
|
if (
|
|
37
41
|
options.baseUrl.charAt(options.baseUrl.length - 1) !== '/' ||
|
|
38
42
|
options.baseUrl.charAt(0) !== '/'
|
|
39
43
|
)
|
|
40
44
|
throw new Error('baseUrl should start and end with a /')
|
|
41
45
|
if (options.mode === 'development') {
|
|
42
|
-
if (!options.vitrifyDir)
|
|
43
|
-
|
|
46
|
+
// if (!options.vitrifyDir)
|
|
47
|
+
// throw new Error('Option vitrifyDir cannot be undefined')
|
|
44
48
|
// if (!options.vite) throw new Error('Option vite cannot be undefined')
|
|
45
49
|
// const { resolve } = await import('import-meta-resolve')
|
|
46
50
|
// const cliDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
47
51
|
options.appDir = options.appDir || new URL('../../..', import.meta.url)
|
|
48
52
|
|
|
49
|
-
const {
|
|
50
|
-
const
|
|
51
|
-
const cliDir = options.vitrifyDir
|
|
52
|
-
const config = await baseConfig({
|
|
53
|
-
ssr: 'server',
|
|
54
|
-
command: 'dev',
|
|
55
|
-
mode: 'development',
|
|
53
|
+
const { createVitrifyDevServer } = await import('vitrify/dev')
|
|
54
|
+
const vite = await createVitrifyDevServer({
|
|
56
55
|
appDir: options.appDir,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
config.server = {
|
|
61
|
-
middlewareMode: true,
|
|
62
|
-
fs: {
|
|
63
|
-
allow: [
|
|
64
|
-
searchForWorkspaceRoot(process.cwd()),
|
|
65
|
-
searchForWorkspaceRoot(options.appDir.pathname),
|
|
66
|
-
searchForWorkspaceRoot(cliDir.pathname)
|
|
67
|
-
// appDir.pathname,
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
watch: {
|
|
71
|
-
// During tests we edit the files too fast and sometimes chokidar
|
|
72
|
-
// misses change events, so enforce polling for consistency
|
|
73
|
-
usePolling: true,
|
|
74
|
-
interval: 100
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const vite = await createServer({
|
|
78
|
-
configFile: false,
|
|
79
|
-
...config
|
|
56
|
+
ssr: 'ssr',
|
|
57
|
+
framework: 'vue',
|
|
58
|
+
base: options.baseUrl
|
|
80
59
|
})
|
|
60
|
+
// const { createServer, searchForWorkspaceRoot } = await import('vite')
|
|
61
|
+
// const { baseConfig } = await import('vitrify')
|
|
62
|
+
// const cliDir = options.vitrifyDir
|
|
63
|
+
// const config = await baseConfig({
|
|
64
|
+
// ssr: 'server',
|
|
65
|
+
// command: 'dev',
|
|
66
|
+
// mode: 'development',
|
|
67
|
+
// appDir: options.appDir,
|
|
68
|
+
// publicDir: options.publicDir || new URL('public', options.appDir)
|
|
69
|
+
// })
|
|
70
|
+
|
|
71
|
+
// config.server = {
|
|
72
|
+
// middlewareMode: true,
|
|
73
|
+
// fs: {
|
|
74
|
+
// allow: [
|
|
75
|
+
// searchForWorkspaceRoot(process.cwd()),
|
|
76
|
+
// searchForWorkspaceRoot(options.appDir.pathname),
|
|
77
|
+
// searchForWorkspaceRoot(cliDir.pathname)
|
|
78
|
+
// // appDir.pathname,
|
|
79
|
+
// ]
|
|
80
|
+
// },
|
|
81
|
+
// watch: {
|
|
82
|
+
// // During tests we edit the files too fast and sometimes chokidar
|
|
83
|
+
// // misses change events, so enforce polling for consistency
|
|
84
|
+
// usePolling: true,
|
|
85
|
+
// interval: 100
|
|
86
|
+
// }
|
|
87
|
+
// }
|
|
88
|
+
// const vite = await createServer({
|
|
89
|
+
// configFile: false,
|
|
90
|
+
// ...config
|
|
91
|
+
// })
|
|
81
92
|
|
|
82
93
|
console.log('Dev mode')
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
if (!('use' in fastify)) {
|
|
95
|
+
const middie = (await import('@fastify/middie')).default
|
|
96
|
+
await fastify.register(middie)
|
|
97
|
+
}
|
|
85
98
|
fastify.use(vite.middlewares)
|
|
86
99
|
|
|
87
100
|
fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
88
101
|
try {
|
|
89
|
-
const url = req.raw.url
|
|
102
|
+
const url = req.raw.url?.replace(options.baseUrl!, '/')
|
|
90
103
|
const ssrContext = {
|
|
91
104
|
req,
|
|
92
105
|
res
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
|
|
108
|
+
let template = readFileSync(
|
|
96
109
|
new URL('index.html', frameworkDir)
|
|
97
110
|
).toString()
|
|
98
111
|
|
|
112
|
+
template = await vite.transformIndexHtml(url!, template)
|
|
113
|
+
|
|
99
114
|
const entryUrl = new URL('ssr/entry-server.ts', frameworkDir).pathname
|
|
100
115
|
const render = (await vite!.ssrLoadModule(entryUrl)).render
|
|
101
116
|
let manifest
|
|
@@ -111,7 +126,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
111
126
|
// if (options.vite?.config.vitrify!.globalCss)
|
|
112
127
|
// cssModules.push(...options.vite?.config.vitrify.globalCss)
|
|
113
128
|
const matchedModules = componentsModules(cssModules, vite!)
|
|
114
|
-
const css = collectCss(
|
|
129
|
+
const css = collectCss({
|
|
130
|
+
mods: matchedModules
|
|
131
|
+
})
|
|
115
132
|
|
|
116
133
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
117
134
|
const html = template
|
|
@@ -3,6 +3,7 @@ import fastify from 'fastify'
|
|
|
3
3
|
import type { ViteDevServer } from 'vite'
|
|
4
4
|
import { getCliDir, getCliViteDir } from '../../app-urls.js'
|
|
5
5
|
import type { OnRenderedHook, OnSetupFile } from '../../vitrify-config.js'
|
|
6
|
+
import type { FastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
6
7
|
import type { FastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
7
8
|
|
|
8
9
|
export const createApp = ({
|
|
@@ -10,7 +11,7 @@ export const createApp = ({
|
|
|
10
11
|
appDir,
|
|
11
12
|
baseUrl,
|
|
12
13
|
onRendered,
|
|
13
|
-
|
|
14
|
+
fastifyPlugin,
|
|
14
15
|
vitrifyDir,
|
|
15
16
|
mode
|
|
16
17
|
}: {
|
|
@@ -18,7 +19,7 @@ export const createApp = ({
|
|
|
18
19
|
appDir: URL
|
|
19
20
|
baseUrl?: string
|
|
20
21
|
onRendered?: OnRenderedHook[]
|
|
21
|
-
|
|
22
|
+
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin
|
|
22
23
|
vitrifyDir?: URL
|
|
23
24
|
mode: string
|
|
24
25
|
}) => {
|
|
@@ -26,7 +27,7 @@ export const createApp = ({
|
|
|
26
27
|
logger: true
|
|
27
28
|
})
|
|
28
29
|
|
|
29
|
-
app.register(
|
|
30
|
+
app.register(fastifyPlugin, {
|
|
30
31
|
baseUrl,
|
|
31
32
|
appDir,
|
|
32
33
|
onRendered,
|
|
@@ -16,11 +16,15 @@ export const componentsModules = (
|
|
|
16
16
|
return matchedModules
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export const collectCss = (
|
|
20
|
-
mods
|
|
19
|
+
export const collectCss = ({
|
|
20
|
+
mods,
|
|
21
21
|
styles = new Map<string, string>(),
|
|
22
22
|
checkedComponents = new Set()
|
|
23
|
-
|
|
23
|
+
}: {
|
|
24
|
+
mods: Set<ModuleNode>
|
|
25
|
+
styles?: Map<string, string>
|
|
26
|
+
checkedComponents?: Set<unknown>
|
|
27
|
+
}) => {
|
|
24
28
|
for (const mod of mods) {
|
|
25
29
|
if (
|
|
26
30
|
(mod.file?.endsWith('.scss') ||
|
|
@@ -32,7 +36,11 @@ export const collectCss = (
|
|
|
32
36
|
}
|
|
33
37
|
if (mod.importedModules.size > 0 && !checkedComponents.has(mod.id)) {
|
|
34
38
|
checkedComponents.add(mod.id)
|
|
35
|
-
collectCss(
|
|
39
|
+
collectCss({
|
|
40
|
+
mods: mod.importedModules,
|
|
41
|
+
styles,
|
|
42
|
+
checkedComponents
|
|
43
|
+
})
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
let result = ''
|
package/src/node/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue'
|
|
2
|
-
import type { InlineConfig, UserConfig } from 'vite'
|
|
2
|
+
import type { Alias, InlineConfig, UserConfig } from 'vite'
|
|
3
3
|
import { resolveConfig } from 'vite'
|
|
4
4
|
import { mergeConfig } from 'vite'
|
|
5
5
|
import { build } from 'esbuild'
|
|
@@ -9,6 +9,7 @@ import { pathToFileURL } from 'url'
|
|
|
9
9
|
import { readFileSync } from 'fs'
|
|
10
10
|
import builtinModules from 'builtin-modules'
|
|
11
11
|
import { resolve } from 'import-meta-resolve'
|
|
12
|
+
import { visualizer } from 'rollup-plugin-visualizer'
|
|
12
13
|
import type {
|
|
13
14
|
StaticImports,
|
|
14
15
|
BootFunction,
|
|
@@ -21,33 +22,16 @@ import type {
|
|
|
21
22
|
import type { VitrifyContext } from './bin/run.js'
|
|
22
23
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
23
24
|
import { getPkgJsonDir } from './app-urls.js'
|
|
24
|
-
import type { RollupOptions } from 'rollup'
|
|
25
|
+
import type { ManualChunksOption, RollupOptions } from 'rollup'
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
// 'fs',
|
|
28
|
-
// 'path',
|
|
29
|
-
// 'url',
|
|
30
|
-
// 'module',
|
|
31
|
-
// 'crypto',
|
|
32
|
-
// 'node:fs',
|
|
27
|
+
const internalServerModules = [
|
|
33
28
|
'util',
|
|
34
|
-
'node:url',
|
|
35
|
-
'node:util',
|
|
36
|
-
'node:fs',
|
|
37
29
|
'vitrify',
|
|
30
|
+
'vitrify/dev',
|
|
38
31
|
'vite',
|
|
39
32
|
'fastify',
|
|
40
|
-
'middie',
|
|
41
|
-
'knex',
|
|
42
|
-
'bcrypt',
|
|
43
|
-
'objection',
|
|
44
|
-
'@fastify/formbody',
|
|
45
33
|
'@fastify/static',
|
|
46
|
-
'
|
|
47
|
-
'@fastify/cookie',
|
|
48
|
-
'mercurius',
|
|
49
|
-
'jose',
|
|
50
|
-
'oidc-provider'
|
|
34
|
+
'node'
|
|
51
35
|
]
|
|
52
36
|
|
|
53
37
|
const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
|
|
@@ -55,7 +39,24 @@ const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
|
|
|
55
39
|
import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
56
40
|
}
|
|
57
41
|
|
|
58
|
-
const
|
|
42
|
+
const manualChunkNames = [
|
|
43
|
+
'prerender',
|
|
44
|
+
'fastify-ssr-plugin',
|
|
45
|
+
'fastify-csr-plugin',
|
|
46
|
+
'server'
|
|
47
|
+
]
|
|
48
|
+
const manualChunks: ManualChunksOption = (id: string) => {
|
|
49
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
50
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
51
|
+
if (name && manualChunkNames.includes(name)) return name
|
|
52
|
+
} else if (
|
|
53
|
+
VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
54
|
+
) {
|
|
55
|
+
return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
56
|
+
} else if (id.includes('node_modules')) {
|
|
57
|
+
return 'vendor'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
59
60
|
|
|
60
61
|
export const VIRTUAL_MODULES = [
|
|
61
62
|
'virtual:vitrify-hooks',
|
|
@@ -125,18 +126,22 @@ export const baseConfig = async ({
|
|
|
125
126
|
ssr,
|
|
126
127
|
appDir,
|
|
127
128
|
publicDir,
|
|
129
|
+
base = '/',
|
|
128
130
|
command = 'build',
|
|
129
131
|
mode = 'production',
|
|
130
132
|
framework = 'vue',
|
|
131
|
-
pwa = false
|
|
133
|
+
pwa = false,
|
|
134
|
+
debug = false
|
|
132
135
|
}: {
|
|
133
136
|
ssr?: 'client' | 'server' | 'ssg' | 'fastify'
|
|
134
137
|
appDir?: URL
|
|
135
138
|
publicDir?: URL
|
|
139
|
+
base?: string
|
|
136
140
|
command?: 'build' | 'dev' | 'test'
|
|
137
141
|
mode?: 'production' | 'development'
|
|
138
142
|
framework?: 'vue'
|
|
139
143
|
pwa?: boolean
|
|
144
|
+
debug?: boolean
|
|
140
145
|
}): Promise<InlineConfig> => {
|
|
141
146
|
const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } =
|
|
142
147
|
await import('./app-urls.js')
|
|
@@ -172,7 +177,7 @@ export const baseConfig = async ({
|
|
|
172
177
|
)
|
|
173
178
|
fs.writeFileSync(configPath + '.js', bundledConfig.code)
|
|
174
179
|
vitrifyConfig = (await import(configPath + '.js')).default
|
|
175
|
-
|
|
180
|
+
fs.unlinkSync(configPath + '.js')
|
|
176
181
|
} else {
|
|
177
182
|
vitrifyConfig = (
|
|
178
183
|
await import(new URL('vitrify.config.js', appDir).pathname)
|
|
@@ -195,6 +200,7 @@ export const baseConfig = async ({
|
|
|
195
200
|
new URL(await resolve(val, appDir!.href))
|
|
196
201
|
)
|
|
197
202
|
})()
|
|
203
|
+
|
|
198
204
|
// await (async () => {
|
|
199
205
|
// for (const val of cliPackages)
|
|
200
206
|
// packageUrls[val] = getPkgJsonDir(
|
|
@@ -241,6 +247,13 @@ export const baseConfig = async ({
|
|
|
241
247
|
let staticImports: StaticImports
|
|
242
248
|
let sassVariables: Record<string, string>
|
|
243
249
|
let additionalData: string[]
|
|
250
|
+
let serverModules: string[] = internalServerModules
|
|
251
|
+
|
|
252
|
+
if (vitrifyConfig.vitrify?.ssr?.serverModules)
|
|
253
|
+
serverModules = [
|
|
254
|
+
...serverModules,
|
|
255
|
+
...vitrifyConfig.vitrify.ssr.serverModules
|
|
256
|
+
]
|
|
244
257
|
|
|
245
258
|
const plugins: UserConfig['plugins'] = [
|
|
246
259
|
vuePlugin({
|
|
@@ -409,9 +422,11 @@ export const baseConfig = async ({
|
|
|
409
422
|
}
|
|
410
423
|
}
|
|
411
424
|
})
|
|
425
|
+
|
|
426
|
+
if (debug) plugins.push(visualizer())
|
|
412
427
|
}
|
|
413
428
|
|
|
414
|
-
const alias = [
|
|
429
|
+
const alias: Alias[] = [
|
|
415
430
|
{ find: 'src', replacement: srcDir.pathname },
|
|
416
431
|
{ find: 'app', replacement: appDir.pathname },
|
|
417
432
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
@@ -425,17 +440,24 @@ export const baseConfig = async ({
|
|
|
425
440
|
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
426
441
|
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
427
442
|
]
|
|
443
|
+
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
444
|
+
alias.push(...vitrifyConfig.vitrify.dev.alias)
|
|
445
|
+
|
|
428
446
|
if (command === 'test')
|
|
429
447
|
alias.push({
|
|
430
448
|
find: 'vitest',
|
|
431
449
|
replacement: new URL(await resolve('vitest', cliDir!.href)).pathname
|
|
432
450
|
})
|
|
433
451
|
|
|
434
|
-
let rollupOptions: RollupOptions
|
|
435
|
-
let noExternal: RegExp[] | string[] = [
|
|
452
|
+
let rollupOptions: RollupOptions = {}
|
|
453
|
+
let noExternal: RegExp[] | string[] = [
|
|
454
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
455
|
+
]
|
|
436
456
|
const external = [...builtinModules, ...serverModules]
|
|
457
|
+
|
|
437
458
|
if (ssr === 'server') {
|
|
438
459
|
rollupOptions = {
|
|
460
|
+
...rollupOptions,
|
|
439
461
|
input: [
|
|
440
462
|
new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
441
463
|
new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
@@ -446,15 +468,16 @@ export const baseConfig = async ({
|
|
|
446
468
|
minifyInternalExports: false,
|
|
447
469
|
entryFileNames: '[name].mjs',
|
|
448
470
|
chunkFileNames: '[name].mjs',
|
|
449
|
-
|
|
450
|
-
manualChunks
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
471
|
+
format: 'es',
|
|
472
|
+
manualChunks
|
|
473
|
+
// manualChunks: (id) => {
|
|
474
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
475
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
476
|
+
// if (name && manualChunks.includes(name)) return name
|
|
477
|
+
// } else if (id.includes('node_modules')) {
|
|
478
|
+
// return 'vendor'
|
|
479
|
+
// }
|
|
480
|
+
// }
|
|
458
481
|
}
|
|
459
482
|
}
|
|
460
483
|
// Create a SSR bundle
|
|
@@ -464,21 +487,23 @@ export const baseConfig = async ({
|
|
|
464
487
|
]
|
|
465
488
|
} else if (ssr === 'fastify') {
|
|
466
489
|
rollupOptions = {
|
|
490
|
+
...rollupOptions,
|
|
467
491
|
input: [new URL('server.ts', fastifyDir).pathname],
|
|
468
492
|
external,
|
|
469
493
|
output: {
|
|
470
494
|
minifyInternalExports: false,
|
|
471
495
|
entryFileNames: '[name].mjs',
|
|
472
496
|
chunkFileNames: '[name].mjs',
|
|
473
|
-
|
|
474
|
-
manualChunks
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
497
|
+
format: 'es',
|
|
498
|
+
manualChunks
|
|
499
|
+
// manualChunks: (id) => {
|
|
500
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
501
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
502
|
+
// if (name && manualChunks.includes(name)) return name
|
|
503
|
+
// } else if (id.includes('node_modules')) {
|
|
504
|
+
// return 'vendor'
|
|
505
|
+
// }
|
|
506
|
+
// }
|
|
482
507
|
}
|
|
483
508
|
}
|
|
484
509
|
// Create a SSR bundle
|
|
@@ -487,16 +512,26 @@ export const baseConfig = async ({
|
|
|
487
512
|
]
|
|
488
513
|
} else {
|
|
489
514
|
rollupOptions = {
|
|
490
|
-
|
|
491
|
-
//
|
|
492
|
-
//
|
|
493
|
-
//
|
|
515
|
+
...rollupOptions,
|
|
516
|
+
// input: [
|
|
517
|
+
// new URL('index.html', frameworkDir).pathname
|
|
518
|
+
// // new URL('csr/server.ts', frameworkDir).pathname
|
|
519
|
+
// ],
|
|
520
|
+
external,
|
|
521
|
+
output: {
|
|
522
|
+
minifyInternalExports: false,
|
|
523
|
+
entryFileNames: '[name].mjs',
|
|
524
|
+
chunkFileNames: '[name].mjs',
|
|
525
|
+
format: 'es',
|
|
526
|
+
manualChunks
|
|
527
|
+
}
|
|
494
528
|
}
|
|
495
529
|
}
|
|
496
530
|
|
|
497
531
|
const config = {
|
|
498
532
|
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
499
533
|
publicDir: publicDir.pathname,
|
|
534
|
+
base,
|
|
500
535
|
envDir: appDir.pathname,
|
|
501
536
|
vitrify: {
|
|
502
537
|
productName,
|
|
@@ -513,11 +548,7 @@ export const baseConfig = async ({
|
|
|
513
548
|
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
514
549
|
},
|
|
515
550
|
resolve: {
|
|
516
|
-
|
|
517
|
-
// dedupe: [
|
|
518
|
-
// 'vue',
|
|
519
|
-
// 'vue-router'
|
|
520
|
-
// ],
|
|
551
|
+
dedupe: ['vue', 'vue-router'],
|
|
521
552
|
alias
|
|
522
553
|
},
|
|
523
554
|
build: {
|
|
@@ -559,11 +590,13 @@ export const baseConfig = async ({
|
|
|
559
590
|
noExternal
|
|
560
591
|
},
|
|
561
592
|
define: {
|
|
562
|
-
__BASE_URL__: `'
|
|
593
|
+
__BASE_URL__: `'${base}'`
|
|
563
594
|
}
|
|
564
595
|
} as VitrifyConfig
|
|
565
596
|
|
|
566
597
|
return mergeConfig(config, vitrifyConfig)
|
|
567
598
|
}
|
|
568
599
|
|
|
600
|
+
export const vitrifyDir = new URL('..', import.meta.url)
|
|
601
|
+
|
|
569
602
|
export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction }
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
import { QuasarResolver } from 'unplugin-vue-components/resolvers'
|
|
14
14
|
import type { VitrifyPlugin } from './index.js'
|
|
15
15
|
import { getPkgJsonDir } from '../app-urls.js'
|
|
16
|
+
|
|
16
17
|
import { resolve } from 'import-meta-resolve'
|
|
17
18
|
|
|
18
19
|
export interface QuasarConf {
|
|
@@ -85,6 +86,29 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
85
86
|
Components({
|
|
86
87
|
resolvers: [QuasarResolver()]
|
|
87
88
|
}),
|
|
89
|
+
{
|
|
90
|
+
name: 'vite-plugin-quasar-transform',
|
|
91
|
+
enforce: 'pre',
|
|
92
|
+
transform: (code, id, options) => {
|
|
93
|
+
const { ssr } = options || {}
|
|
94
|
+
code = code
|
|
95
|
+
.replaceAll('__QUASAR_SSR__', ssr ? ssr.toString() : 'false')
|
|
96
|
+
.replaceAll(
|
|
97
|
+
'__QUASAR_SSR_SERVER__',
|
|
98
|
+
ssr ? 'import.meta.env.SSR' : 'false'
|
|
99
|
+
)
|
|
100
|
+
.replaceAll(
|
|
101
|
+
'__QUASAR_SSR_CLIENT__',
|
|
102
|
+
ssr ? '!import.meta.env.SSR' : 'false'
|
|
103
|
+
)
|
|
104
|
+
.replaceAll(
|
|
105
|
+
'__QUASAR_SSR_PWA__',
|
|
106
|
+
ssr && pwa ? '!import.meta.env.SSR' : 'false'
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
return code
|
|
110
|
+
}
|
|
111
|
+
},
|
|
88
112
|
{
|
|
89
113
|
name: 'vite-plugin-quasar-setup',
|
|
90
114
|
enforce: 'pre',
|
|
@@ -225,10 +249,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
225
249
|
replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
226
250
|
.pathname
|
|
227
251
|
},
|
|
228
|
-
// {
|
|
229
|
-
// find: 'quasar',
|
|
230
|
-
// replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
|
|
231
|
-
// },
|
|
232
252
|
{
|
|
233
253
|
find: `@quasar/extras`,
|
|
234
254
|
replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
@@ -238,11 +258,14 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
238
258
|
},
|
|
239
259
|
define: {
|
|
240
260
|
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
241
|
-
__QUASAR_VERSION__: `'${version}'
|
|
242
|
-
__QUASAR_SSR__: !!ssr,
|
|
243
|
-
__QUASAR_SSR_SERVER__: ssr === 'server',
|
|
244
|
-
|
|
245
|
-
|
|
261
|
+
__QUASAR_VERSION__: `'${version}'`
|
|
262
|
+
// __QUASAR_SSR__: !!ssr,
|
|
263
|
+
// // __QUASAR_SSR_SERVER__: ssr === 'server',
|
|
264
|
+
// __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
|
|
265
|
+
// // __QUASAR_SSR_CLIENT__: ssr === 'client',
|
|
266
|
+
// __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
|
|
267
|
+
// // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
|
|
268
|
+
// __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
|
|
246
269
|
},
|
|
247
270
|
ssr: {
|
|
248
271
|
noExternal: ['quasar']
|
|
@@ -256,7 +279,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
256
279
|
config: async (config, env) => ({
|
|
257
280
|
resolve: {
|
|
258
281
|
alias: [
|
|
259
|
-
|
|
282
|
+
{ find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
260
283
|
]
|
|
261
284
|
}
|
|
262
285
|
}),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { UserConfig } from 'vite'
|
|
1
|
+
import type { Alias, UserConfig } from 'vite'
|
|
3
2
|
import type { QuasarConf } from './plugins/quasar.js'
|
|
4
3
|
import type { ComponentInternalInstance } from '@vue/runtime-core'
|
|
5
4
|
|
|
@@ -87,6 +86,18 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
87
86
|
cwd?: URL
|
|
88
87
|
packages?: Record<string, URL>
|
|
89
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* SSR specific configuration
|
|
91
|
+
*/
|
|
92
|
+
ssr?: {
|
|
93
|
+
serverModules?: string[]
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Development only configuration
|
|
97
|
+
*/
|
|
98
|
+
dev?: {
|
|
99
|
+
alias?: Alias[]
|
|
100
|
+
}
|
|
90
101
|
}
|
|
91
102
|
quasar?: QuasarConf
|
|
92
103
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
|
+
import { getAppDir } from '../../../node/app-urls.js'
|
|
3
|
+
// import { setup } from 'virtual:fastify-setup'
|
|
4
|
+
import { onRendered, onSetup } from 'virtual:vitrify-hooks'
|
|
5
|
+
import { fastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
6
|
+
import type { ViteDevServer } from 'vite'
|
|
7
|
+
import * as imr from 'import-meta-resolve'
|
|
8
|
+
const { resolve } = imr
|
|
9
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
10
|
+
const getString = (str?: string) => str
|
|
11
|
+
let baseUrl = getString(__BASE_URL__)
|
|
12
|
+
const appDir = getAppDir()
|
|
13
|
+
|
|
14
|
+
export const setupApp = async () => {
|
|
15
|
+
const vitrifyDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
16
|
+
return createApp({
|
|
17
|
+
onSetup,
|
|
18
|
+
appDir,
|
|
19
|
+
baseUrl,
|
|
20
|
+
onRendered,
|
|
21
|
+
fastifyPlugin: fastifyCsrPlugin,
|
|
22
|
+
vitrifyDir,
|
|
23
|
+
mode: import.meta.env.MODE
|
|
24
|
+
})
|
|
25
|
+
}
|