vitrify 0.2.4 → 0.4.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/dist/app-urls.js +1 -2
- package/dist/bin/build.js +0 -43
- package/dist/bin/cli.js +29 -7
- package/dist/bin/dev.js +58 -67
- package/dist/frameworks/vue/fastify-ssr-plugin.js +67 -23
- package/dist/frameworks/vue/prerender.js +3 -3
- package/dist/frameworks/vue/server.js +9 -10
- package/dist/helpers/collect-css-ssr.js +57 -0
- package/dist/helpers/logger.js +0 -72
- package/dist/index.js +268 -122
- package/dist/plugins/quasar.js +13 -106
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +39 -3
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/prerender.d.ts +3 -3
- package/dist/types/frameworks/vue/server.d.ts +9 -5
- package/dist/types/helpers/collect-css-ssr.d.ts +10 -0
- package/dist/types/helpers/logger.d.ts +0 -19
- package/dist/types/helpers/routes.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/vitrify-config.d.ts +20 -16
- package/package.json +32 -32
- package/src/node/app-urls.ts +1 -2
- package/src/node/bin/build.ts +2 -49
- package/src/node/bin/cli.ts +36 -8
- package/src/node/bin/dev.ts +89 -75
- package/src/node/bin/test.ts +0 -3
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +80 -26
- package/src/node/frameworks/vue/prerender.ts +5 -5
- package/src/node/frameworks/vue/server.ts +22 -16
- package/src/node/helpers/collect-css-ssr.ts +77 -0
- package/src/node/helpers/logger.ts +0 -87
- package/src/node/index.ts +302 -137
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +14 -111
- package/src/node/vitrify-config.ts +31 -16
- package/src/vite/fastify/entry.ts +11 -0
- package/src/vite/fastify/server.ts +10 -0
- package/src/vite/vue/index.html +1 -0
- package/src/vite/vue/main.ts +5 -20
- package/src/vite/vue/ssr/app.ts +25 -0
- package/src/vite/vue/ssr/entry-server.ts +13 -1
- package/src/vite/vue/ssr/fastify-ssr-plugin.ts +2 -118
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/src/vite/vue/ssr/server.ts +24 -15
- package/src/node/helpers/ssr.ts.bak +0 -52
package/src/node/index.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue'
|
|
2
2
|
import type { 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
|
-
import { QuasarPlugin } from './plugins/quasar.js'
|
|
6
10
|
import builtinModules from 'builtin-modules'
|
|
7
11
|
import { resolve } from 'import-meta-resolve'
|
|
8
12
|
import type {
|
|
@@ -10,29 +14,113 @@ import type {
|
|
|
10
14
|
BootFunction,
|
|
11
15
|
OnMountedHook,
|
|
12
16
|
VitrifyConfig,
|
|
13
|
-
|
|
17
|
+
OnRenderedHook,
|
|
18
|
+
OnBootHook,
|
|
19
|
+
OnSetupFile
|
|
14
20
|
} from './vitrify-config.js'
|
|
15
21
|
import type { VitrifyContext } from './bin/run.js'
|
|
16
22
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
17
|
-
import type { FastifyInstance } from 'fastify'
|
|
18
23
|
import { getPkgJsonDir } from './app-urls.js'
|
|
24
|
+
import type { RollupOptions } from 'rollup'
|
|
19
25
|
|
|
20
|
-
const serverModules = [
|
|
26
|
+
const serverModules = [
|
|
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
|
+
'vitrify',
|
|
38
|
+
'vite',
|
|
39
|
+
'fastify',
|
|
40
|
+
'middie',
|
|
41
|
+
'knex',
|
|
42
|
+
'bcrypt',
|
|
43
|
+
'objection',
|
|
44
|
+
'@fastify/formbody',
|
|
45
|
+
'@fastify/static',
|
|
46
|
+
'@fastify/cors',
|
|
47
|
+
'@fastify/cookie',
|
|
48
|
+
'mercurius',
|
|
49
|
+
'jose',
|
|
50
|
+
'oidc-provider'
|
|
51
|
+
]
|
|
21
52
|
|
|
22
53
|
const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
|
|
23
54
|
quasar: () =>
|
|
24
55
|
import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
25
56
|
}
|
|
26
57
|
|
|
58
|
+
const manualChunks = ['prerender', 'fastify-ssr-plugin', 'server']
|
|
59
|
+
|
|
27
60
|
export const VIRTUAL_MODULES = [
|
|
28
|
-
'virtual:
|
|
29
|
-
'virtual:boot-functions',
|
|
30
|
-
'virtual:ssr-functions',
|
|
31
|
-
'virtual:on-mounted-hooks',
|
|
61
|
+
'virtual:vitrify-hooks',
|
|
32
62
|
'virtual:global-css',
|
|
33
63
|
'virtual:static-imports'
|
|
34
64
|
]
|
|
35
65
|
|
|
66
|
+
async function bundleConfigFile(
|
|
67
|
+
fileName: string,
|
|
68
|
+
isESM = false
|
|
69
|
+
): Promise<{ code: string; dependencies: string[] }> {
|
|
70
|
+
const result = await build({
|
|
71
|
+
absWorkingDir: process.cwd(),
|
|
72
|
+
entryPoints: [fileName],
|
|
73
|
+
outfile: 'out.js',
|
|
74
|
+
write: false,
|
|
75
|
+
platform: 'node',
|
|
76
|
+
bundle: true,
|
|
77
|
+
format: 'esm',
|
|
78
|
+
sourcemap: 'inline',
|
|
79
|
+
metafile: true,
|
|
80
|
+
plugins: [
|
|
81
|
+
{
|
|
82
|
+
name: 'externalize-deps',
|
|
83
|
+
setup(build) {
|
|
84
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
85
|
+
const id = args.path
|
|
86
|
+
if (id[0] !== '.' && !path.isAbsolute(id)) {
|
|
87
|
+
return {
|
|
88
|
+
external: true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'replace-import-meta',
|
|
96
|
+
setup(build) {
|
|
97
|
+
build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
|
|
98
|
+
const contents = await fs.promises.readFile(args.path, 'utf8')
|
|
99
|
+
return {
|
|
100
|
+
loader: args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
101
|
+
contents: contents
|
|
102
|
+
.replace(
|
|
103
|
+
/\bimport\.meta\.url\b/g,
|
|
104
|
+
JSON.stringify(pathToFileURL(args.path).href)
|
|
105
|
+
)
|
|
106
|
+
.replace(
|
|
107
|
+
/\b__dirname\b/g,
|
|
108
|
+
JSON.stringify(path.dirname(args.path))
|
|
109
|
+
)
|
|
110
|
+
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
const { text } = result.outputFiles[0]
|
|
118
|
+
return {
|
|
119
|
+
code: text,
|
|
120
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
36
124
|
export const baseConfig = async ({
|
|
37
125
|
ssr,
|
|
38
126
|
appDir,
|
|
@@ -42,7 +130,7 @@ export const baseConfig = async ({
|
|
|
42
130
|
framework = 'vue',
|
|
43
131
|
pwa = false
|
|
44
132
|
}: {
|
|
45
|
-
ssr?: 'client' | 'server' | 'ssg'
|
|
133
|
+
ssr?: 'client' | 'server' | 'ssg' | 'fastify'
|
|
46
134
|
appDir?: URL
|
|
47
135
|
publicDir?: URL
|
|
48
136
|
command?: 'build' | 'dev' | 'test'
|
|
@@ -59,43 +147,8 @@ export const baseConfig = async ({
|
|
|
59
147
|
const cwd = getCwd()
|
|
60
148
|
const cliDir = getCliDir()
|
|
61
149
|
const cliViteDir = getCliViteDir(cliDir)
|
|
62
|
-
// const {
|
|
63
|
-
// appDir: tempAppDir,
|
|
64
|
-
// cliDir,
|
|
65
|
-
// cliViteDir,
|
|
66
|
-
// srcDir
|
|
67
|
-
// } = await import('./app-urls.js')
|
|
68
|
-
// const cwd = appDir || tempAppDir
|
|
69
150
|
const frameworkDir = new URL(`${framework}/`, cliViteDir)
|
|
70
|
-
|
|
71
|
-
// const localPackages = ['vue', 'vue-router', 'quasar']
|
|
72
|
-
const localPackages = ['vue', 'vue-router']
|
|
73
|
-
const cliPackages = ['vitest']
|
|
74
|
-
const packageUrls: Record<string, URL> = {}
|
|
75
|
-
await (async () => {
|
|
76
|
-
for (const val of localPackages)
|
|
77
|
-
packageUrls[val] = getPkgJsonDir(
|
|
78
|
-
new URL(await resolve(val, appDir!.href))
|
|
79
|
-
)
|
|
80
|
-
})()
|
|
81
|
-
await (async () => {
|
|
82
|
-
for (const val of cliPackages)
|
|
83
|
-
packageUrls[val] = getPkgJsonDir(
|
|
84
|
-
new URL(await resolve(val, cliDir!.href))
|
|
85
|
-
)
|
|
86
|
-
})()
|
|
87
|
-
|
|
88
|
-
// if (appDir) {
|
|
89
|
-
// srcDir = new URL('src/', appDir);
|
|
90
|
-
// quasarDir = new URL(await resolve('quasar/', appDir.href));
|
|
91
|
-
// ({ appDir: cwd, cliDir } = await import('./app-urls.js'))
|
|
92
|
-
// } else {
|
|
93
|
-
// ({ appDir, cliDir, srcDir, quasarDir } = await import('./app-urls.js'))
|
|
94
|
-
// cwd = appDir
|
|
95
|
-
// }
|
|
96
|
-
// vueDir = new URL('./', await resolve('vue', appDir.href));
|
|
97
|
-
// vueRouterDir = new URL('../', await resolve('vue-router', appDir.href));
|
|
98
|
-
// vitestDir = new URL('../', await resolve('vitest', cliDir.href));
|
|
151
|
+
const fastifyDir = new URL('fastify/', cliViteDir)
|
|
99
152
|
|
|
100
153
|
if (!publicDir) publicDir = new URL('public/', appDir)
|
|
101
154
|
/**
|
|
@@ -103,27 +156,62 @@ export const baseConfig = async ({
|
|
|
103
156
|
*/
|
|
104
157
|
let vitrifyConfig:
|
|
105
158
|
| VitrifyConfig
|
|
106
|
-
| (({
|
|
159
|
+
| (({
|
|
160
|
+
mode,
|
|
161
|
+
command
|
|
162
|
+
}: {
|
|
163
|
+
mode: string
|
|
164
|
+
command: string
|
|
165
|
+
}) => Promise<VitrifyConfig> | VitrifyConfig)
|
|
107
166
|
|
|
108
167
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
168
|
+
if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
|
|
169
|
+
const configPath = new URL('vitrify.config.ts', appDir).pathname
|
|
170
|
+
const bundledConfig = await bundleConfigFile(
|
|
171
|
+
new URL('vitrify.config.ts', appDir).pathname
|
|
172
|
+
)
|
|
173
|
+
fs.writeFileSync(configPath + '.js', bundledConfig.code)
|
|
174
|
+
vitrifyConfig = (await import(configPath + '.js')).default
|
|
175
|
+
// fs.unlinkSync(configPath + '.js')
|
|
176
|
+
} else {
|
|
177
|
+
vitrifyConfig = (
|
|
178
|
+
await import(new URL('vitrify.config.js', appDir).pathname)
|
|
179
|
+
).default
|
|
180
|
+
}
|
|
112
181
|
if (typeof vitrifyConfig === 'function')
|
|
113
|
-
vitrifyConfig = vitrifyConfig({ mode, command })
|
|
182
|
+
vitrifyConfig = await vitrifyConfig({ mode, command })
|
|
114
183
|
} catch (e) {
|
|
115
|
-
console.
|
|
116
|
-
console.log('No vitrify.config.js file found, using defaults')
|
|
184
|
+
console.log('No vitrify.config.(ts|js) file found, using defaults')
|
|
117
185
|
vitrifyConfig = {}
|
|
118
186
|
}
|
|
119
|
-
let { productName = 'Product name' } = JSON.parse(
|
|
120
|
-
readFileSync(new URL('package.json', appDir).pathname, {
|
|
121
|
-
encoding: 'utf-8'
|
|
122
|
-
})
|
|
123
|
-
)
|
|
124
187
|
|
|
125
|
-
const
|
|
126
|
-
|
|
188
|
+
const localPackages = ['vue', 'vue-router']
|
|
189
|
+
const cliPackages = []
|
|
190
|
+
const packageUrls: Record<string, URL> =
|
|
191
|
+
vitrifyConfig.vitrify?.urls?.packages || {}
|
|
192
|
+
await (async () => {
|
|
193
|
+
for (const val of localPackages)
|
|
194
|
+
packageUrls[val] = getPkgJsonDir(
|
|
195
|
+
new URL(await resolve(val, appDir!.href))
|
|
196
|
+
)
|
|
197
|
+
})()
|
|
198
|
+
// await (async () => {
|
|
199
|
+
// for (const val of cliPackages)
|
|
200
|
+
// packageUrls[val] = getPkgJsonDir(
|
|
201
|
+
// new URL(await resolve(val, cliDir!.href))
|
|
202
|
+
// )
|
|
203
|
+
// })()
|
|
204
|
+
|
|
205
|
+
let productName = 'Product name'
|
|
206
|
+
try {
|
|
207
|
+
;({ productName } = JSON.parse(
|
|
208
|
+
readFileSync(new URL('package.json', appDir).pathname, {
|
|
209
|
+
encoding: 'utf-8'
|
|
210
|
+
})
|
|
211
|
+
))
|
|
212
|
+
} catch (e) {
|
|
213
|
+
console.error('package.json not found')
|
|
214
|
+
}
|
|
127
215
|
|
|
128
216
|
const ssrTransformCustomDir = () => {
|
|
129
217
|
return {
|
|
@@ -145,9 +233,10 @@ export const baseConfig = async ({
|
|
|
145
233
|
}
|
|
146
234
|
}
|
|
147
235
|
|
|
148
|
-
let
|
|
149
|
-
let
|
|
236
|
+
let onBootHooks: OnBootHook[]
|
|
237
|
+
let onRenderedHooks: OnRenderedHook[]
|
|
150
238
|
let onMountedHooks: OnMountedHook[]
|
|
239
|
+
let onSetupFiles: OnSetupFile[]
|
|
151
240
|
let globalCss: string[]
|
|
152
241
|
let staticImports: StaticImports
|
|
153
242
|
let sassVariables: Record<string, string>
|
|
@@ -155,6 +244,7 @@ export const baseConfig = async ({
|
|
|
155
244
|
|
|
156
245
|
const plugins: UserConfig['plugins'] = [
|
|
157
246
|
vuePlugin({
|
|
247
|
+
compiler: await import('vue/compiler-sfc'),
|
|
158
248
|
template: {
|
|
159
249
|
ssr: !!ssr,
|
|
160
250
|
compilerOptions: {
|
|
@@ -175,18 +265,14 @@ export const baseConfig = async ({
|
|
|
175
265
|
}
|
|
176
266
|
}),
|
|
177
267
|
...frameworkPlugins,
|
|
178
|
-
// await QuasarPlugin({
|
|
179
|
-
// ssr: ssr,
|
|
180
|
-
// pwa: pwa
|
|
181
|
-
// // quasarDir: packageUrls.quasar
|
|
182
|
-
// }),
|
|
183
268
|
{
|
|
184
269
|
name: 'vitrify-setup',
|
|
185
270
|
enforce: 'post',
|
|
186
271
|
config: async (config: VitrifyConfig, env) => {
|
|
187
|
-
|
|
188
|
-
|
|
272
|
+
onBootHooks = config.vitrify?.hooks?.onBoot || []
|
|
273
|
+
onRenderedHooks = config.vitrify?.hooks?.onRendered || []
|
|
189
274
|
onMountedHooks = config.vitrify?.hooks?.onMounted || []
|
|
275
|
+
onSetupFiles = config?.vitrify?.hooks?.onSetup || []
|
|
190
276
|
globalCss = config.vitrify?.globalCss || []
|
|
191
277
|
staticImports = config.vitrify?.staticImports || {}
|
|
192
278
|
sassVariables = config.vitrify?.sass?.variables || {}
|
|
@@ -215,26 +301,49 @@ export const baseConfig = async ({
|
|
|
215
301
|
}
|
|
216
302
|
},
|
|
217
303
|
resolveId(id) {
|
|
218
|
-
if (VIRTUAL_MODULES.includes(id))
|
|
304
|
+
if (VIRTUAL_MODULES.includes(id))
|
|
305
|
+
return { id, moduleSideEffects: false }
|
|
219
306
|
return
|
|
220
307
|
},
|
|
308
|
+
transform: (code, id) => {
|
|
309
|
+
if (id.endsWith('main.ts') && id.includes('vitrify')) {
|
|
310
|
+
code =
|
|
311
|
+
`${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
|
|
312
|
+
}
|
|
313
|
+
return code
|
|
314
|
+
},
|
|
221
315
|
load(id) {
|
|
222
|
-
if (id === 'virtual:
|
|
223
|
-
return `export const
|
|
224
|
-
} else if (id === 'virtual:boot-functions') {
|
|
225
|
-
return `export default [${bootFunctions
|
|
226
|
-
.map((fn) => `${String(fn)}`)
|
|
227
|
-
.join(', ')}]`
|
|
228
|
-
} else if (id === 'virtual:ssr-functions') {
|
|
229
|
-
return `export default [${ssrFunctions
|
|
316
|
+
if (id === 'virtual:vitrify-hooks') {
|
|
317
|
+
return `export const onBoot = [${onBootHooks
|
|
230
318
|
.map((fn) => `${String(fn)}`)
|
|
231
|
-
.join(', ')}]
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
319
|
+
.join(', ')}]
|
|
320
|
+
export const onMounted = [${onMountedHooks
|
|
321
|
+
.map((fn) => `${String(fn)}`)
|
|
322
|
+
.join(', ')}]
|
|
323
|
+
export const onRendered = [${onRenderedHooks
|
|
324
|
+
.map((fn) => `${String(fn)}`)
|
|
325
|
+
.join(', ')}]
|
|
326
|
+
export const onSetup = []
|
|
327
|
+
${onSetupFiles
|
|
328
|
+
.map(
|
|
329
|
+
(url, index) =>
|
|
330
|
+
`import ${url.pathname
|
|
331
|
+
.replaceAll('/', '')
|
|
332
|
+
.replaceAll('.', '')} from '${
|
|
333
|
+
url.pathname
|
|
334
|
+
}'; onSetup.push(${url.pathname
|
|
335
|
+
.replaceAll('/', '')
|
|
336
|
+
.replaceAll('.', '')})`
|
|
337
|
+
)
|
|
338
|
+
.join('\n')}`
|
|
339
|
+
// export const onSetup = [${onSetupHooks
|
|
340
|
+
// .map((fn) => `${String(fn)}`)
|
|
341
|
+
// .join(', ')}]`
|
|
342
|
+
/**
|
|
343
|
+
* CSS imports in virtual files do not seem to work. Using transform() instead
|
|
344
|
+
*/
|
|
345
|
+
// } else if (id === 'virtual:global-css') {
|
|
346
|
+
// return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
|
|
238
347
|
} else if (id === 'virtual:static-imports') {
|
|
239
348
|
return `${Object.entries(staticImports)
|
|
240
349
|
.map(
|
|
@@ -270,6 +379,9 @@ export const baseConfig = async ({
|
|
|
270
379
|
case 'client':
|
|
271
380
|
entry = new URL('ssr/entry-client.ts', frameworkDir).pathname
|
|
272
381
|
break
|
|
382
|
+
case 'fastify':
|
|
383
|
+
entry = new URL('entry.ts', fastifyDir).pathname
|
|
384
|
+
break
|
|
273
385
|
default:
|
|
274
386
|
entry = new URL('csr/entry.ts', frameworkDir).pathname
|
|
275
387
|
}
|
|
@@ -305,26 +417,90 @@ export const baseConfig = async ({
|
|
|
305
417
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
306
418
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
307
419
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
{ find: 'vue
|
|
313
|
-
{ find: '
|
|
420
|
+
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
421
|
+
find: key,
|
|
422
|
+
replacement: value.pathname
|
|
423
|
+
}))
|
|
424
|
+
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
425
|
+
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
426
|
+
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
314
427
|
]
|
|
315
428
|
if (command === 'test')
|
|
316
429
|
alias.push({
|
|
317
430
|
find: 'vitest',
|
|
318
|
-
replacement:
|
|
431
|
+
replacement: new URL(await resolve('vitest', cliDir!.href)).pathname
|
|
319
432
|
})
|
|
320
433
|
|
|
434
|
+
let rollupOptions: RollupOptions
|
|
435
|
+
let noExternal: RegExp[] | string[] = []
|
|
436
|
+
const external = [...builtinModules, ...serverModules]
|
|
437
|
+
if (ssr === 'server') {
|
|
438
|
+
rollupOptions = {
|
|
439
|
+
input: [
|
|
440
|
+
new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
441
|
+
new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
442
|
+
new URL('ssr/server.ts', frameworkDir).pathname
|
|
443
|
+
],
|
|
444
|
+
external,
|
|
445
|
+
output: {
|
|
446
|
+
minifyInternalExports: false,
|
|
447
|
+
entryFileNames: '[name].mjs',
|
|
448
|
+
chunkFileNames: '[name].mjs',
|
|
449
|
+
// format: 'es',
|
|
450
|
+
manualChunks: (id) => {
|
|
451
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
452
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
453
|
+
if (name && manualChunks.includes(name)) return name
|
|
454
|
+
} else if (id.includes('node_modules')) {
|
|
455
|
+
return 'vendor'
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// Create a SSR bundle
|
|
461
|
+
noExternal = [
|
|
462
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
463
|
+
// new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
464
|
+
]
|
|
465
|
+
} else if (ssr === 'fastify') {
|
|
466
|
+
rollupOptions = {
|
|
467
|
+
input: [new URL('server.ts', fastifyDir).pathname],
|
|
468
|
+
external,
|
|
469
|
+
output: {
|
|
470
|
+
minifyInternalExports: false,
|
|
471
|
+
entryFileNames: '[name].mjs',
|
|
472
|
+
chunkFileNames: '[name].mjs',
|
|
473
|
+
// format: 'es',
|
|
474
|
+
manualChunks: (id) => {
|
|
475
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
476
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
477
|
+
if (name && manualChunks.includes(name)) return name
|
|
478
|
+
} else if (id.includes('node_modules')) {
|
|
479
|
+
return 'vendor'
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
// Create a SSR bundle
|
|
485
|
+
noExternal = [
|
|
486
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
487
|
+
]
|
|
488
|
+
} else {
|
|
489
|
+
rollupOptions = {
|
|
490
|
+
// input: [new URL('index.html', frameworkDir).pathname],
|
|
491
|
+
// output: {
|
|
492
|
+
// format: 'es'
|
|
493
|
+
// }
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
321
497
|
const config = {
|
|
322
|
-
root: frameworkDir.pathname,
|
|
498
|
+
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
323
499
|
publicDir: publicDir.pathname,
|
|
500
|
+
envDir: appDir.pathname,
|
|
324
501
|
vitrify: {
|
|
325
502
|
productName,
|
|
326
503
|
urls: {
|
|
327
|
-
// @ts-ignore
|
|
328
504
|
app: appDir,
|
|
329
505
|
cli: cliDir,
|
|
330
506
|
src: srcDir,
|
|
@@ -334,7 +510,7 @@ export const baseConfig = async ({
|
|
|
334
510
|
},
|
|
335
511
|
plugins,
|
|
336
512
|
optimizeDeps: {
|
|
337
|
-
exclude: ['vue']
|
|
513
|
+
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
338
514
|
},
|
|
339
515
|
resolve: {
|
|
340
516
|
// Dedupe uses require which breaks ESM SSR builds
|
|
@@ -345,53 +521,42 @@ export const baseConfig = async ({
|
|
|
345
521
|
alias
|
|
346
522
|
},
|
|
347
523
|
build: {
|
|
348
|
-
target: ssr === 'server' ? 'esnext' : 'modules',
|
|
349
|
-
ssr: ssr === 'server' ? true : false,
|
|
524
|
+
target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
|
|
525
|
+
ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
|
|
350
526
|
ssrManifest: ssr === 'client' || ssr === 'ssg',
|
|
351
|
-
rollupOptions
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
527
|
+
rollupOptions
|
|
528
|
+
// ssr === 'server'
|
|
529
|
+
// ? {
|
|
530
|
+
// input: [
|
|
531
|
+
// new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
532
|
+
// new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
533
|
+
// new URL('ssr/server.ts', frameworkDir).pathname
|
|
534
|
+
// ],
|
|
535
|
+
// output: {
|
|
536
|
+
// minifyInternalExports: false,
|
|
537
|
+
// entryFileNames: '[name].mjs',
|
|
538
|
+
// chunkFileNames: '[name].mjs',
|
|
539
|
+
// format: 'es',
|
|
540
|
+
// manualChunks: (id) => {
|
|
541
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
542
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
543
|
+
// if (name && manualChunks.includes(name)) return name
|
|
544
|
+
// } else if (id.includes('node_modules')) {
|
|
545
|
+
// return 'vendor'
|
|
546
|
+
// }
|
|
547
|
+
// }
|
|
548
|
+
// }
|
|
549
|
+
// }
|
|
550
|
+
// : {
|
|
551
|
+
// output: {
|
|
552
|
+
// format: 'es'
|
|
553
|
+
// }
|
|
554
|
+
// }
|
|
380
555
|
},
|
|
381
|
-
// css: {
|
|
382
|
-
// preprocessorOptions: {
|
|
383
|
-
// sass: {
|
|
384
|
-
// additionalData: sass ? [...sass].join('\n') : undefined
|
|
385
|
-
// }
|
|
386
|
-
// }
|
|
387
|
-
// },
|
|
388
556
|
ssr: {
|
|
389
557
|
// Create a SSR bundle
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`
|
|
393
|
-
)
|
|
394
|
-
]
|
|
558
|
+
external,
|
|
559
|
+
noExternal
|
|
395
560
|
},
|
|
396
561
|
define: {
|
|
397
562
|
__BASE_URL__: `'/'`
|