vitrify 0.2.5 → 0.5.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/README.md +2 -2
- package/dist/app-urls.js +1 -2
- package/dist/bin/build.js +9 -51
- package/dist/bin/cli.js +31 -9
- package/dist/bin/dev.js +72 -70
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -25
- package/dist/frameworks/vue/prerender.js +3 -3
- package/dist/frameworks/vue/server.js +10 -11
- package/dist/helpers/collect-css-ssr.js +61 -0
- package/dist/helpers/logger.js +0 -72
- package/dist/index.js +310 -130
- package/dist/plugins/quasar.js +34 -111
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +42 -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/prerender.d.ts +3 -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/logger.d.ts +0 -19
- 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 +33 -17
- package/package.json +33 -32
- package/src/node/app-urls.ts +1 -2
- package/src/node/bin/build.ts +11 -57
- package/src/node/bin/cli.ts +38 -10
- package/src/node/bin/dev.ts +106 -80
- package/src/node/bin/test.ts +0 -3
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -28
- package/src/node/frameworks/vue/prerender.ts +5 -5
- package/src/node/frameworks/vue/server.ts +24 -17
- package/src/node/helpers/collect-css-ssr.ts +85 -0
- package/src/node/helpers/logger.ts +0 -87
- package/src/node/index.ts +353 -146
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +39 -116
- package/src/node/vitrify-config.ts +44 -17
- 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 +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/dist/index.js
CHANGED
|
@@ -1,23 +1,118 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue';
|
|
2
2
|
import { mergeConfig } from 'vite';
|
|
3
|
+
import { build } from 'esbuild';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { pathToFileURL } from 'url';
|
|
3
7
|
import { readFileSync } from 'fs';
|
|
4
8
|
import builtinModules from 'builtin-modules';
|
|
5
9
|
import { resolve } from 'import-meta-resolve';
|
|
6
10
|
import { getPkgJsonDir } from './app-urls.js';
|
|
7
|
-
const
|
|
11
|
+
const internalServerModules = [
|
|
12
|
+
// 'fs',
|
|
13
|
+
// 'path',
|
|
14
|
+
// 'url',
|
|
15
|
+
// 'module',
|
|
16
|
+
// 'crypto',
|
|
17
|
+
// 'node:fs',
|
|
18
|
+
'util',
|
|
19
|
+
'node:url',
|
|
20
|
+
'node:util',
|
|
21
|
+
'node:fs',
|
|
22
|
+
'node:process',
|
|
23
|
+
'vitrify',
|
|
24
|
+
'vitrify/dev',
|
|
25
|
+
// 'import-meta-resolve',
|
|
26
|
+
'vite',
|
|
27
|
+
'fastify',
|
|
28
|
+
'@fastify',
|
|
29
|
+
'node'
|
|
30
|
+
// 'middie',
|
|
31
|
+
// 'knex',
|
|
32
|
+
// 'bcrypt',
|
|
33
|
+
// 'objection',
|
|
34
|
+
// '@fastify/formbody',
|
|
35
|
+
// '@fastify/static',
|
|
36
|
+
// '@fastify/cors',
|
|
37
|
+
// '@fastify/cookie',
|
|
38
|
+
// 'mercurius',
|
|
39
|
+
// 'jose',
|
|
40
|
+
// 'oidc-provider',
|
|
41
|
+
// 'node-fetch'
|
|
42
|
+
];
|
|
8
43
|
const configPluginMap = {
|
|
9
44
|
quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
10
45
|
};
|
|
11
|
-
const
|
|
46
|
+
const manualChunkNames = [
|
|
47
|
+
'prerender',
|
|
48
|
+
'fastify-ssr-plugin',
|
|
49
|
+
'fastify-csr-plugin',
|
|
50
|
+
'server'
|
|
51
|
+
];
|
|
52
|
+
const manualChunks = (id) => {
|
|
53
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
54
|
+
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
55
|
+
if (name && manualChunkNames.includes(name))
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
else if (id.includes('node_modules')) {
|
|
59
|
+
return 'vendor';
|
|
60
|
+
}
|
|
61
|
+
};
|
|
12
62
|
export const VIRTUAL_MODULES = [
|
|
13
|
-
'virtual:
|
|
14
|
-
'virtual:boot-functions',
|
|
15
|
-
'virtual:ssr-functions',
|
|
16
|
-
'virtual:on-mounted-hooks',
|
|
63
|
+
'virtual:vitrify-hooks',
|
|
17
64
|
'virtual:global-css',
|
|
18
65
|
'virtual:static-imports'
|
|
19
66
|
];
|
|
20
|
-
|
|
67
|
+
async function bundleConfigFile(fileName, isESM = false) {
|
|
68
|
+
const result = await build({
|
|
69
|
+
absWorkingDir: process.cwd(),
|
|
70
|
+
entryPoints: [fileName],
|
|
71
|
+
outfile: 'out.js',
|
|
72
|
+
write: false,
|
|
73
|
+
platform: 'node',
|
|
74
|
+
bundle: true,
|
|
75
|
+
format: 'esm',
|
|
76
|
+
sourcemap: 'inline',
|
|
77
|
+
metafile: true,
|
|
78
|
+
plugins: [
|
|
79
|
+
{
|
|
80
|
+
name: 'externalize-deps',
|
|
81
|
+
setup(build) {
|
|
82
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
83
|
+
const id = args.path;
|
|
84
|
+
if (id[0] !== '.' && !path.isAbsolute(id)) {
|
|
85
|
+
return {
|
|
86
|
+
external: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'replace-import-meta',
|
|
94
|
+
setup(build) {
|
|
95
|
+
build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
|
|
96
|
+
const contents = await fs.promises.readFile(args.path, 'utf8');
|
|
97
|
+
return {
|
|
98
|
+
loader: args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
99
|
+
contents: contents
|
|
100
|
+
.replace(/\bimport\.meta\.url\b/g, JSON.stringify(pathToFileURL(args.path).href))
|
|
101
|
+
.replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path)))
|
|
102
|
+
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
});
|
|
109
|
+
const { text } = result.outputFiles[0];
|
|
110
|
+
return {
|
|
111
|
+
code: text,
|
|
112
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
|
|
21
116
|
const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
|
|
22
117
|
if (!appDir) {
|
|
23
118
|
appDir = getAppDir();
|
|
@@ -26,37 +121,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
26
121
|
const cwd = getCwd();
|
|
27
122
|
const cliDir = getCliDir();
|
|
28
123
|
const cliViteDir = getCliViteDir(cliDir);
|
|
29
|
-
// const {
|
|
30
|
-
// appDir: tempAppDir,
|
|
31
|
-
// cliDir,
|
|
32
|
-
// cliViteDir,
|
|
33
|
-
// srcDir
|
|
34
|
-
// } = await import('./app-urls.js')
|
|
35
|
-
// const cwd = appDir || tempAppDir
|
|
36
124
|
const frameworkDir = new URL(`${framework}/`, cliViteDir);
|
|
37
|
-
|
|
38
|
-
const localPackages = ['vue', 'vue-router'];
|
|
39
|
-
const cliPackages = ['vitest'];
|
|
40
|
-
const packageUrls = {};
|
|
41
|
-
await (async () => {
|
|
42
|
-
for (const val of localPackages)
|
|
43
|
-
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
|
|
44
|
-
})();
|
|
45
|
-
await (async () => {
|
|
46
|
-
for (const val of cliPackages)
|
|
47
|
-
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, cliDir.href)));
|
|
48
|
-
})();
|
|
49
|
-
// if (appDir) {
|
|
50
|
-
// srcDir = new URL('src/', appDir);
|
|
51
|
-
// quasarDir = new URL(await resolve('quasar/', appDir.href));
|
|
52
|
-
// ({ appDir: cwd, cliDir } = await import('./app-urls.js'))
|
|
53
|
-
// } else {
|
|
54
|
-
// ({ appDir, cliDir, srcDir, quasarDir } = await import('./app-urls.js'))
|
|
55
|
-
// cwd = appDir
|
|
56
|
-
// }
|
|
57
|
-
// vueDir = new URL('./', await resolve('vue', appDir.href));
|
|
58
|
-
// vueRouterDir = new URL('../', await resolve('vue-router', appDir.href));
|
|
59
|
-
// vitestDir = new URL('../', await resolve('vitest', cliDir.href));
|
|
125
|
+
const fastifyDir = new URL('fastify/', cliViteDir);
|
|
60
126
|
if (!publicDir)
|
|
61
127
|
publicDir = new URL('public/', appDir);
|
|
62
128
|
/**
|
|
@@ -64,19 +130,46 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
64
130
|
*/
|
|
65
131
|
let vitrifyConfig;
|
|
66
132
|
try {
|
|
67
|
-
|
|
133
|
+
if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
|
|
134
|
+
const configPath = new URL('vitrify.config.ts', appDir).pathname;
|
|
135
|
+
const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir).pathname);
|
|
136
|
+
fs.writeFileSync(configPath + '.js', bundledConfig.code);
|
|
137
|
+
vitrifyConfig = (await import(configPath + '.js')).default;
|
|
138
|
+
fs.unlinkSync(configPath + '.js');
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
|
|
142
|
+
}
|
|
68
143
|
if (typeof vitrifyConfig === 'function')
|
|
69
|
-
vitrifyConfig = vitrifyConfig({ mode, command });
|
|
144
|
+
vitrifyConfig = await vitrifyConfig({ mode, command });
|
|
70
145
|
}
|
|
71
146
|
catch (e) {
|
|
72
|
-
console.
|
|
73
|
-
console.log('No vitrify.config.js file found, using defaults');
|
|
147
|
+
console.log('No vitrify.config.(ts|js) file found, using defaults');
|
|
74
148
|
vitrifyConfig = {};
|
|
75
149
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
150
|
+
const localPackages = ['vue', 'vue-router'];
|
|
151
|
+
const cliPackages = [];
|
|
152
|
+
const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
|
|
153
|
+
await (async () => {
|
|
154
|
+
for (const val of localPackages)
|
|
155
|
+
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
|
|
156
|
+
})();
|
|
157
|
+
// await (async () => {
|
|
158
|
+
// for (const val of cliPackages)
|
|
159
|
+
// packageUrls[val] = getPkgJsonDir(
|
|
160
|
+
// new URL(await resolve(val, cliDir!.href))
|
|
161
|
+
// )
|
|
162
|
+
// })()
|
|
163
|
+
let productName = 'Product name';
|
|
164
|
+
try {
|
|
165
|
+
;
|
|
166
|
+
({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
|
|
167
|
+
encoding: 'utf-8'
|
|
168
|
+
})));
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
console.error('package.json not found');
|
|
172
|
+
}
|
|
80
173
|
const ssrTransformCustomDir = () => {
|
|
81
174
|
return {
|
|
82
175
|
props: [],
|
|
@@ -93,15 +186,23 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
93
186
|
}));
|
|
94
187
|
}
|
|
95
188
|
}
|
|
96
|
-
let
|
|
97
|
-
let
|
|
189
|
+
let onBootHooks;
|
|
190
|
+
let onRenderedHooks;
|
|
98
191
|
let onMountedHooks;
|
|
192
|
+
let onSetupFiles;
|
|
99
193
|
let globalCss;
|
|
100
194
|
let staticImports;
|
|
101
195
|
let sassVariables;
|
|
102
196
|
let additionalData;
|
|
197
|
+
let serverModules = internalServerModules;
|
|
198
|
+
if (vitrifyConfig.vitrify?.ssr?.serverModules)
|
|
199
|
+
serverModules = [
|
|
200
|
+
...serverModules,
|
|
201
|
+
...vitrifyConfig.vitrify.ssr.serverModules
|
|
202
|
+
];
|
|
103
203
|
const plugins = [
|
|
104
204
|
vuePlugin({
|
|
205
|
+
compiler: await import('vue/compiler-sfc'),
|
|
105
206
|
template: {
|
|
106
207
|
ssr: !!ssr,
|
|
107
208
|
compilerOptions: {
|
|
@@ -122,18 +223,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
122
223
|
}
|
|
123
224
|
}),
|
|
124
225
|
...frameworkPlugins,
|
|
125
|
-
// await QuasarPlugin({
|
|
126
|
-
// ssr: ssr,
|
|
127
|
-
// pwa: pwa
|
|
128
|
-
// // quasarDir: packageUrls.quasar
|
|
129
|
-
// }),
|
|
130
226
|
{
|
|
131
227
|
name: 'vitrify-setup',
|
|
132
228
|
enforce: 'post',
|
|
133
229
|
config: async (config, env) => {
|
|
134
|
-
|
|
135
|
-
|
|
230
|
+
onBootHooks = config.vitrify?.hooks?.onBoot || [];
|
|
231
|
+
onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
|
|
136
232
|
onMountedHooks = config.vitrify?.hooks?.onMounted || [];
|
|
233
|
+
onSetupFiles = config?.vitrify?.hooks?.onSetup || [];
|
|
137
234
|
globalCss = config.vitrify?.globalCss || [];
|
|
138
235
|
staticImports = config.vitrify?.staticImports || {};
|
|
139
236
|
sassVariables = config.vitrify?.sass?.variables || {};
|
|
@@ -160,30 +257,43 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
160
257
|
},
|
|
161
258
|
resolveId(id) {
|
|
162
259
|
if (VIRTUAL_MODULES.includes(id))
|
|
163
|
-
return id;
|
|
260
|
+
return { id, moduleSideEffects: false };
|
|
164
261
|
return;
|
|
165
262
|
},
|
|
166
|
-
|
|
167
|
-
if (id
|
|
168
|
-
|
|
263
|
+
transform: (code, id) => {
|
|
264
|
+
if (id.endsWith('main.ts') && id.includes('vitrify')) {
|
|
265
|
+
code =
|
|
266
|
+
`${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
|
|
169
267
|
}
|
|
170
|
-
|
|
171
|
-
|
|
268
|
+
return code;
|
|
269
|
+
},
|
|
270
|
+
load(id) {
|
|
271
|
+
if (id === 'virtual:vitrify-hooks') {
|
|
272
|
+
return `export const onBoot = [${onBootHooks
|
|
172
273
|
.map((fn) => `${String(fn)}`)
|
|
173
|
-
.join(', ')}]
|
|
174
|
-
|
|
175
|
-
else if (id === 'virtual:ssr-functions') {
|
|
176
|
-
return `export default [${ssrFunctions
|
|
274
|
+
.join(', ')}]
|
|
275
|
+
export const onMounted = [${onMountedHooks
|
|
177
276
|
.map((fn) => `${String(fn)}`)
|
|
178
|
-
.join(', ')}]
|
|
179
|
-
|
|
180
|
-
else if (id === 'virtual:on-mounted-hooks') {
|
|
181
|
-
return `export default [${onMountedHooks
|
|
277
|
+
.join(', ')}]
|
|
278
|
+
export const onRendered = [${onRenderedHooks
|
|
182
279
|
.map((fn) => `${String(fn)}`)
|
|
183
|
-
.join(', ')}]
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
280
|
+
.join(', ')}]
|
|
281
|
+
export const onSetup = []
|
|
282
|
+
${onSetupFiles
|
|
283
|
+
.map((url, index) => `import ${url.pathname
|
|
284
|
+
.replaceAll('/', '')
|
|
285
|
+
.replaceAll('.', '')} from '${url.pathname}'; onSetup.push(${url.pathname
|
|
286
|
+
.replaceAll('/', '')
|
|
287
|
+
.replaceAll('.', '')})`)
|
|
288
|
+
.join('\n')}`;
|
|
289
|
+
// export const onSetup = [${onSetupHooks
|
|
290
|
+
// .map((fn) => `${String(fn)}`)
|
|
291
|
+
// .join(', ')}]`
|
|
292
|
+
/**
|
|
293
|
+
* CSS imports in virtual files do not seem to work. Using transform() instead
|
|
294
|
+
*/
|
|
295
|
+
// } else if (id === 'virtual:global-css') {
|
|
296
|
+
// return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
|
|
187
297
|
}
|
|
188
298
|
else if (id === 'virtual:static-imports') {
|
|
189
299
|
return `${Object.entries(staticImports)
|
|
@@ -218,6 +328,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
218
328
|
case 'client':
|
|
219
329
|
entry = new URL('ssr/entry-client.ts', frameworkDir).pathname;
|
|
220
330
|
break;
|
|
331
|
+
case 'fastify':
|
|
332
|
+
entry = new URL('entry.ts', fastifyDir).pathname;
|
|
333
|
+
break;
|
|
221
334
|
default:
|
|
222
335
|
entry = new URL('csr/entry.ts', frameworkDir).pathname;
|
|
223
336
|
}
|
|
@@ -251,25 +364,105 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
251
364
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
252
365
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
253
366
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
{ find: 'vue
|
|
259
|
-
{ find: '
|
|
367
|
+
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
368
|
+
find: key,
|
|
369
|
+
replacement: value.pathname
|
|
370
|
+
}))
|
|
371
|
+
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
372
|
+
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
373
|
+
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
260
374
|
];
|
|
375
|
+
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
376
|
+
alias.push(...vitrifyConfig.vitrify.dev.alias);
|
|
261
377
|
if (command === 'test')
|
|
262
378
|
alias.push({
|
|
263
379
|
find: 'vitest',
|
|
264
|
-
replacement:
|
|
380
|
+
replacement: new URL(await resolve('vitest', cliDir.href)).pathname
|
|
265
381
|
});
|
|
382
|
+
let rollupOptions = {};
|
|
383
|
+
let noExternal = [
|
|
384
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
385
|
+
];
|
|
386
|
+
const external = [...builtinModules, ...serverModules];
|
|
387
|
+
if (ssr === 'server') {
|
|
388
|
+
rollupOptions = {
|
|
389
|
+
input: [
|
|
390
|
+
new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
391
|
+
new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
392
|
+
new URL('ssr/server.ts', frameworkDir).pathname
|
|
393
|
+
],
|
|
394
|
+
external,
|
|
395
|
+
output: {
|
|
396
|
+
minifyInternalExports: false,
|
|
397
|
+
entryFileNames: '[name].mjs',
|
|
398
|
+
chunkFileNames: '[name].mjs',
|
|
399
|
+
format: 'es',
|
|
400
|
+
manualChunks
|
|
401
|
+
// manualChunks: (id) => {
|
|
402
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
403
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
404
|
+
// if (name && manualChunks.includes(name)) return name
|
|
405
|
+
// } else if (id.includes('node_modules')) {
|
|
406
|
+
// return 'vendor'
|
|
407
|
+
// }
|
|
408
|
+
// }
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
// Create a SSR bundle
|
|
412
|
+
noExternal = [
|
|
413
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
414
|
+
// new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
else if (ssr === 'fastify') {
|
|
418
|
+
rollupOptions = {
|
|
419
|
+
input: [new URL('server.ts', fastifyDir).pathname],
|
|
420
|
+
external,
|
|
421
|
+
output: {
|
|
422
|
+
minifyInternalExports: false,
|
|
423
|
+
entryFileNames: '[name].mjs',
|
|
424
|
+
chunkFileNames: '[name].mjs',
|
|
425
|
+
format: 'es',
|
|
426
|
+
manualChunks
|
|
427
|
+
// manualChunks: (id) => {
|
|
428
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
429
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
430
|
+
// if (name && manualChunks.includes(name)) return name
|
|
431
|
+
// } else if (id.includes('node_modules')) {
|
|
432
|
+
// return 'vendor'
|
|
433
|
+
// }
|
|
434
|
+
// }
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
// Create a SSR bundle
|
|
438
|
+
noExternal = [
|
|
439
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
440
|
+
];
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
rollupOptions = {
|
|
444
|
+
input: [
|
|
445
|
+
new URL('index.html', frameworkDir).pathname
|
|
446
|
+
// new URL('csr/server.ts', frameworkDir).pathname
|
|
447
|
+
],
|
|
448
|
+
external,
|
|
449
|
+
output: {
|
|
450
|
+
minifyInternalExports: false,
|
|
451
|
+
entryFileNames: '[name].mjs',
|
|
452
|
+
chunkFileNames: '[name].mjs',
|
|
453
|
+
format: 'es',
|
|
454
|
+
manualChunks
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
266
458
|
const config = {
|
|
267
|
-
root: frameworkDir.pathname,
|
|
459
|
+
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
268
460
|
publicDir: publicDir.pathname,
|
|
461
|
+
base,
|
|
462
|
+
envDir: appDir.pathname,
|
|
269
463
|
vitrify: {
|
|
270
464
|
productName,
|
|
271
465
|
urls: {
|
|
272
|
-
// @ts-ignore
|
|
273
466
|
app: appDir,
|
|
274
467
|
cli: cliDir,
|
|
275
468
|
src: srcDir,
|
|
@@ -279,67 +472,54 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
279
472
|
},
|
|
280
473
|
plugins,
|
|
281
474
|
optimizeDeps: {
|
|
282
|
-
exclude: ['vue']
|
|
475
|
+
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
283
476
|
},
|
|
284
477
|
resolve: {
|
|
285
|
-
|
|
286
|
-
// dedupe: [
|
|
287
|
-
// 'vue',
|
|
288
|
-
// 'vue-router'
|
|
289
|
-
// ],
|
|
478
|
+
dedupe: ['vue', 'vue-router'],
|
|
290
479
|
alias
|
|
291
480
|
},
|
|
292
481
|
build: {
|
|
293
|
-
target: ssr === 'server' ? 'esnext' : 'modules',
|
|
294
|
-
ssr: ssr === 'server' ? true : false,
|
|
482
|
+
target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
|
|
483
|
+
ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
|
|
295
484
|
ssrManifest: ssr === 'client' || ssr === 'ssg',
|
|
296
|
-
rollupOptions
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
}
|
|
485
|
+
rollupOptions
|
|
486
|
+
// ssr === 'server'
|
|
487
|
+
// ? {
|
|
488
|
+
// input: [
|
|
489
|
+
// new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
490
|
+
// new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
491
|
+
// new URL('ssr/server.ts', frameworkDir).pathname
|
|
492
|
+
// ],
|
|
493
|
+
// output: {
|
|
494
|
+
// minifyInternalExports: false,
|
|
495
|
+
// entryFileNames: '[name].mjs',
|
|
496
|
+
// chunkFileNames: '[name].mjs',
|
|
497
|
+
// format: 'es',
|
|
498
|
+
// manualChunks: (id) => {
|
|
499
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
500
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
501
|
+
// if (name && manualChunks.includes(name)) return name
|
|
502
|
+
// } else if (id.includes('node_modules')) {
|
|
503
|
+
// return 'vendor'
|
|
504
|
+
// }
|
|
505
|
+
// }
|
|
506
|
+
// }
|
|
507
|
+
// }
|
|
508
|
+
// : {
|
|
509
|
+
// output: {
|
|
510
|
+
// format: 'es'
|
|
511
|
+
// }
|
|
512
|
+
// }
|
|
326
513
|
},
|
|
327
|
-
// css: {
|
|
328
|
-
// preprocessorOptions: {
|
|
329
|
-
// sass: {
|
|
330
|
-
// additionalData: sass ? [...sass].join('\n') : undefined
|
|
331
|
-
// }
|
|
332
|
-
// }
|
|
333
|
-
// },
|
|
334
514
|
ssr: {
|
|
335
515
|
// Create a SSR bundle
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
]
|
|
516
|
+
external,
|
|
517
|
+
noExternal
|
|
339
518
|
},
|
|
340
519
|
define: {
|
|
341
|
-
__BASE_URL__: `'
|
|
520
|
+
__BASE_URL__: `'${base}'`
|
|
342
521
|
}
|
|
343
522
|
};
|
|
344
523
|
return mergeConfig(config, vitrifyConfig);
|
|
345
524
|
};
|
|
525
|
+
export const vitrifyDir = new URL('..', import.meta.url);
|