vitrify 0.4.0 → 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/bin/build.js +9 -8
- package/dist/bin/cli.js +3 -3
- package/dist/bin/dev.js +35 -24
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +52 -38
- package/dist/frameworks/vue/server.js +2 -2
- package/dist/helpers/collect-css-ssr.js +6 -2
- package/dist/index.js +84 -49
- package/dist/plugins/quasar.js +21 -5
- package/dist/types/bin/dev.d.ts +6 -4
- 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 +3 -1
- package/dist/types/vitrify-config.d.ts +13 -1
- package/package.json +6 -5
- package/src/node/bin/build.ts +9 -8
- package/src/node/bin/cli.ts +3 -3
- package/src/node/bin/dev.ts +40 -28
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +56 -39
- package/src/node/frameworks/vue/server.ts +4 -3
- package/src/node/helpers/collect-css-ssr.ts +12 -4
- package/src/node/index.ts +90 -46
- package/src/node/plugins/quasar.ts +25 -5
- package/src/node/vitrify-config.ts +13 -1
- 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
package/README.md
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
> Pre-configured Vite CLI for your framework
|
|
4
4
|
|
|
5
5
|
- Use a simple configuration file to configure and integrate required Vite plugins into your project.
|
|
6
|
-
- Client-Side Rendering (CSR)
|
|
6
|
+
- Client-Side Rendering (CSR), Server-Side Rendering (SSR) and Fastify server build and development modes.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- Uses [Fastify](https://github.com/fastify/fastify-vite) for the development server and SSR production server.
|
|
11
|
-
|
|
11
|
+
- Generates a Fastify plugin to serve your server-side rendered application.
|
|
12
12
|
- A [`run`](./src/node/bin/run.ts) command which injects context such as application paths into the script which you want to run.
|
|
13
13
|
- A [`test`](./src/node/bin/test.ts) command which runs a pre-configured [Vitest](https://github.com/vitest-dev/vitest) instance.
|
|
14
14
|
- An [extra plugin layer](./src/node/plugins/index.ts) which provides some extra context such as the SSR mode (client or server) and PWA mode. Used for UI frameworks which render differently based on these settings.
|
package/dist/bin/build.js
CHANGED
|
@@ -7,7 +7,8 @@ export async function build(opts) {
|
|
|
7
7
|
mode: 'production',
|
|
8
8
|
ssr: opts?.ssr,
|
|
9
9
|
appDir: opts.appDir,
|
|
10
|
-
publicDir: opts.publicDir
|
|
10
|
+
publicDir: opts.publicDir,
|
|
11
|
+
base: opts.base
|
|
11
12
|
});
|
|
12
13
|
config.build = {
|
|
13
14
|
...config.build,
|
|
@@ -15,15 +16,15 @@ export async function build(opts) {
|
|
|
15
16
|
outDir: opts.outDir,
|
|
16
17
|
emptyOutDir: !!opts.outDir
|
|
17
18
|
};
|
|
18
|
-
if (opts.base) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
19
|
+
// if (opts.base) {
|
|
20
|
+
// config.define = {
|
|
21
|
+
// ...config.define,
|
|
22
|
+
// __BASE_URL__: `'${opts.base}'`
|
|
23
|
+
// }
|
|
24
|
+
// }
|
|
24
25
|
return viteBuild({
|
|
25
26
|
configFile: false,
|
|
26
|
-
base: opts.base,
|
|
27
|
+
// base: opts.base,
|
|
27
28
|
// logLevel: 'silent',
|
|
28
29
|
...config
|
|
29
30
|
});
|
package/dist/bin/cli.js
CHANGED
|
@@ -33,7 +33,7 @@ cli
|
|
|
33
33
|
case 'csr':
|
|
34
34
|
await build({
|
|
35
35
|
...args,
|
|
36
|
-
outDir: new URL('
|
|
36
|
+
outDir: new URL('csr/', baseOutDir).pathname
|
|
37
37
|
});
|
|
38
38
|
break;
|
|
39
39
|
case 'fastify':
|
|
@@ -106,7 +106,7 @@ cli
|
|
|
106
106
|
case 'ssr':
|
|
107
107
|
;
|
|
108
108
|
({ server, config } = await createServer({
|
|
109
|
-
|
|
109
|
+
ssr: 'ssr',
|
|
110
110
|
host: options.host,
|
|
111
111
|
appDir: parsePath(options.appDir, cwd),
|
|
112
112
|
publicDir: parsePath(options.publicDir, cwd)
|
|
@@ -115,7 +115,7 @@ cli
|
|
|
115
115
|
case 'fastify':
|
|
116
116
|
;
|
|
117
117
|
({ server, config } = await createServer({
|
|
118
|
-
|
|
118
|
+
ssr: 'fastify',
|
|
119
119
|
host: options.host,
|
|
120
120
|
appDir: parsePath(options.appDir, cwd),
|
|
121
121
|
publicDir: parsePath(options.publicDir, cwd)
|
package/dist/bin/dev.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { searchForWorkspaceRoot } from 'vite';
|
|
2
2
|
import { baseConfig } from '../index.js';
|
|
3
3
|
import fastify from 'fastify';
|
|
4
|
-
|
|
4
|
+
import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
|
|
5
|
+
export async function createVitrifyDevServer({ port = 3000, logLevel = 'info',
|
|
6
|
+
// mode = 'csr',
|
|
7
|
+
ssr, framework = 'vue', host, appDir, publicDir, base }) {
|
|
5
8
|
const { getAppDir, getCliDir, getCliViteDir, getCwd } = await import('../app-urls.js');
|
|
6
9
|
const cliDir = getCliDir();
|
|
7
10
|
if (!appDir)
|
|
8
11
|
appDir = getAppDir();
|
|
9
12
|
let config = {};
|
|
10
13
|
let ssrMode;
|
|
11
|
-
if (
|
|
14
|
+
if (ssr === 'ssr')
|
|
12
15
|
ssrMode = 'server';
|
|
13
|
-
if (
|
|
16
|
+
if (ssr === 'fastify')
|
|
14
17
|
ssrMode = 'fastify';
|
|
15
18
|
config = await baseConfig({
|
|
16
19
|
framework,
|
|
@@ -18,22 +21,26 @@ export async function createVitrifyDevServer({ port = 3000, logLevel = 'info', m
|
|
|
18
21
|
command: 'dev',
|
|
19
22
|
mode: 'development',
|
|
20
23
|
appDir,
|
|
21
|
-
publicDir
|
|
24
|
+
publicDir,
|
|
25
|
+
base
|
|
22
26
|
});
|
|
23
27
|
config.logLevel = logLevel;
|
|
28
|
+
console.log(searchForWorkspaceRoot(appDir.pathname));
|
|
24
29
|
config.server = {
|
|
25
30
|
https: config.server?.https,
|
|
31
|
+
hmr: {
|
|
32
|
+
protocol: config.server?.https ? 'wss' : 'ws'
|
|
33
|
+
},
|
|
26
34
|
port,
|
|
27
35
|
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
|
|
28
|
-
middlewareMode:
|
|
36
|
+
middlewareMode: ssr ? 'ssr' : false,
|
|
29
37
|
fs: {
|
|
38
|
+
strict: false,
|
|
30
39
|
allow: [
|
|
31
40
|
searchForWorkspaceRoot(process.cwd()),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
searchForWorkspaceRoot(cliDir.pathname)
|
|
36
|
-
// appDir.pathname,
|
|
41
|
+
searchForWorkspaceRoot(appDir.pathname),
|
|
42
|
+
searchForWorkspaceRoot(cliDir.pathname),
|
|
43
|
+
appDir.pathname
|
|
37
44
|
]
|
|
38
45
|
},
|
|
39
46
|
watch: {
|
|
@@ -50,42 +57,46 @@ export async function createVitrifyDevServer({ port = 3000, logLevel = 'info', m
|
|
|
50
57
|
});
|
|
51
58
|
return vitrifyDevServer;
|
|
52
59
|
}
|
|
53
|
-
export async function createServer({ port = 3000, logLevel = 'info',
|
|
60
|
+
export async function createServer({ port = 3000, logLevel = 'info',
|
|
61
|
+
// mode = 'csr',
|
|
62
|
+
ssr, framework = 'vue', host, appDir, publicDir }) {
|
|
54
63
|
const { getAppDir, getCliDir, getCliViteDir, getCwd } = await import('../app-urls.js');
|
|
64
|
+
appDir = appDir || getAppDir();
|
|
55
65
|
const cliDir = getCliDir();
|
|
56
66
|
const vite = await createVitrifyDevServer({
|
|
57
67
|
port,
|
|
58
68
|
logLevel,
|
|
59
|
-
|
|
69
|
+
ssr,
|
|
60
70
|
framework,
|
|
61
71
|
host,
|
|
62
72
|
appDir,
|
|
63
73
|
publicDir
|
|
64
74
|
});
|
|
65
|
-
let entryUrl;
|
|
66
75
|
let setup;
|
|
67
76
|
let server;
|
|
68
|
-
console.log(`Development mode: ${
|
|
69
|
-
if (
|
|
70
|
-
const entryUrl =
|
|
77
|
+
console.log(`Development mode: ${ssr ? ssr : 'csr'}`);
|
|
78
|
+
if (ssr) {
|
|
79
|
+
const entryUrl = ssr === 'fastify'
|
|
71
80
|
? new URL('src/vite/fastify/entry.ts', cliDir).pathname
|
|
72
81
|
: new URL(`src/vite/${framework}/ssr/entry-server.ts`, cliDir).pathname;
|
|
73
82
|
({ setup } = await vite.ssrLoadModule(entryUrl));
|
|
74
83
|
const app = fastify({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: {}
|
|
84
|
+
logger: true,
|
|
85
|
+
https: vite.config.server.https
|
|
78
86
|
});
|
|
87
|
+
if (process.env)
|
|
88
|
+
process.env.MODE = 'development';
|
|
79
89
|
if (setup) {
|
|
80
90
|
await setup({
|
|
81
91
|
fastify: app
|
|
82
92
|
});
|
|
83
93
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
if (ssr === 'ssr') {
|
|
95
|
+
await app.register(fastifySsrPlugin, {
|
|
96
|
+
appDir,
|
|
97
|
+
mode: 'development'
|
|
98
|
+
});
|
|
99
|
+
}
|
|
89
100
|
await app.listen({
|
|
90
101
|
port: Number(port || 3000),
|
|
91
102
|
host
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fastifyStatic from '@fastify/static';
|
|
2
|
+
const fastifyCsrPlugin = async (fastify, options, done) => {
|
|
3
|
+
options.vitrifyDir =
|
|
4
|
+
options.vitrifyDir || (await import('vitrify')).vitrifyDir;
|
|
5
|
+
const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir);
|
|
6
|
+
options.baseUrl = options.baseUrl || '/';
|
|
7
|
+
options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
|
|
8
|
+
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
9
|
+
if (options.baseUrl.charAt(options.baseUrl.length - 1) !== '/' ||
|
|
10
|
+
options.baseUrl.charAt(0) !== '/')
|
|
11
|
+
throw new Error('baseUrl should start and end with a /');
|
|
12
|
+
if (options.mode === 'development') {
|
|
13
|
+
options.appDir = options.appDir || new URL('../..', import.meta.url);
|
|
14
|
+
const { createVitrifyDevServer } = await import('vitrify/dev');
|
|
15
|
+
const vite = await createVitrifyDevServer({
|
|
16
|
+
appDir: options.appDir,
|
|
17
|
+
framework: 'vue',
|
|
18
|
+
base: options.baseUrl
|
|
19
|
+
});
|
|
20
|
+
console.log('Dev mode');
|
|
21
|
+
if (!('use' in fastify)) {
|
|
22
|
+
const middie = (await import('@fastify/middie')).default;
|
|
23
|
+
await fastify.register(middie);
|
|
24
|
+
}
|
|
25
|
+
fastify.use(vite.middlewares);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
29
|
+
fastify.register(fastifyStatic, {
|
|
30
|
+
root: new URL('./dist/csr', options.appDir).pathname,
|
|
31
|
+
wildcard: false,
|
|
32
|
+
index: false,
|
|
33
|
+
prefix: options.baseUrl
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
done();
|
|
37
|
+
};
|
|
38
|
+
export { fastifyCsrPlugin };
|
|
@@ -3,62 +3,74 @@ import { readFileSync } from 'fs';
|
|
|
3
3
|
import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js';
|
|
4
4
|
const fastifySsrPlugin = async (fastify, options, done) => {
|
|
5
5
|
options.vitrifyDir =
|
|
6
|
-
options.vitrifyDir ||
|
|
7
|
-
const frameworkDir = new URL('vite/vue/', options.vitrifyDir);
|
|
6
|
+
options.vitrifyDir || (await import('vitrify')).vitrifyDir;
|
|
7
|
+
const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir);
|
|
8
8
|
options.baseUrl = options.baseUrl || '/';
|
|
9
|
+
options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
|
|
10
|
+
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
9
11
|
if (options.baseUrl.charAt(options.baseUrl.length - 1) !== '/' ||
|
|
10
12
|
options.baseUrl.charAt(0) !== '/')
|
|
11
13
|
throw new Error('baseUrl should start and end with a /');
|
|
12
14
|
if (options.mode === 'development') {
|
|
13
|
-
if (!options.vitrifyDir)
|
|
14
|
-
|
|
15
|
+
// if (!options.vitrifyDir)
|
|
16
|
+
// throw new Error('Option vitrifyDir cannot be undefined')
|
|
15
17
|
// if (!options.vite) throw new Error('Option vite cannot be undefined')
|
|
16
18
|
// const { resolve } = await import('import-meta-resolve')
|
|
17
19
|
// const cliDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
18
20
|
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
19
|
-
const {
|
|
20
|
-
const
|
|
21
|
-
const cliDir = options.vitrifyDir;
|
|
22
|
-
const config = await baseConfig({
|
|
23
|
-
ssr: 'server',
|
|
24
|
-
command: 'dev',
|
|
25
|
-
mode: 'development',
|
|
21
|
+
const { createVitrifyDevServer } = await import('vitrify/dev');
|
|
22
|
+
const vite = await createVitrifyDevServer({
|
|
26
23
|
appDir: options.appDir,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
middlewareMode: true,
|
|
31
|
-
fs: {
|
|
32
|
-
allow: [
|
|
33
|
-
searchForWorkspaceRoot(process.cwd()),
|
|
34
|
-
searchForWorkspaceRoot(options.appDir.pathname),
|
|
35
|
-
searchForWorkspaceRoot(cliDir.pathname)
|
|
36
|
-
// appDir.pathname,
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
watch: {
|
|
40
|
-
// During tests we edit the files too fast and sometimes chokidar
|
|
41
|
-
// misses change events, so enforce polling for consistency
|
|
42
|
-
usePolling: true,
|
|
43
|
-
interval: 100
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const vite = await createServer({
|
|
47
|
-
configFile: false,
|
|
48
|
-
...config
|
|
24
|
+
ssr: 'ssr',
|
|
25
|
+
framework: 'vue',
|
|
26
|
+
base: options.baseUrl
|
|
49
27
|
});
|
|
28
|
+
// const { createServer, searchForWorkspaceRoot } = await import('vite')
|
|
29
|
+
// const { baseConfig } = await import('vitrify')
|
|
30
|
+
// const cliDir = options.vitrifyDir
|
|
31
|
+
// const config = await baseConfig({
|
|
32
|
+
// ssr: 'server',
|
|
33
|
+
// command: 'dev',
|
|
34
|
+
// mode: 'development',
|
|
35
|
+
// appDir: options.appDir,
|
|
36
|
+
// publicDir: options.publicDir || new URL('public', options.appDir)
|
|
37
|
+
// })
|
|
38
|
+
// config.server = {
|
|
39
|
+
// middlewareMode: true,
|
|
40
|
+
// fs: {
|
|
41
|
+
// allow: [
|
|
42
|
+
// searchForWorkspaceRoot(process.cwd()),
|
|
43
|
+
// searchForWorkspaceRoot(options.appDir.pathname),
|
|
44
|
+
// searchForWorkspaceRoot(cliDir.pathname)
|
|
45
|
+
// // appDir.pathname,
|
|
46
|
+
// ]
|
|
47
|
+
// },
|
|
48
|
+
// watch: {
|
|
49
|
+
// // During tests we edit the files too fast and sometimes chokidar
|
|
50
|
+
// // misses change events, so enforce polling for consistency
|
|
51
|
+
// usePolling: true,
|
|
52
|
+
// interval: 100
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
|
+
// const vite = await createServer({
|
|
56
|
+
// configFile: false,
|
|
57
|
+
// ...config
|
|
58
|
+
// })
|
|
50
59
|
console.log('Dev mode');
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
if (!('use' in fastify)) {
|
|
61
|
+
const middie = (await import('@fastify/middie')).default;
|
|
62
|
+
await fastify.register(middie);
|
|
63
|
+
}
|
|
53
64
|
fastify.use(vite.middlewares);
|
|
54
65
|
fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
55
66
|
try {
|
|
56
|
-
const url = req.raw.url;
|
|
67
|
+
const url = req.raw.url?.replace(options.baseUrl, '/');
|
|
57
68
|
const ssrContext = {
|
|
58
69
|
req,
|
|
59
70
|
res
|
|
60
71
|
};
|
|
61
|
-
|
|
72
|
+
let template = readFileSync(new URL('index.html', frameworkDir)).toString();
|
|
73
|
+
template = await vite.transformIndexHtml(url, template);
|
|
62
74
|
const entryUrl = new URL('ssr/entry-server.ts', frameworkDir).pathname;
|
|
63
75
|
const render = (await vite.ssrLoadModule(entryUrl)).render;
|
|
64
76
|
let manifest;
|
|
@@ -74,7 +86,9 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
74
86
|
// if (options.vite?.config.vitrify!.globalCss)
|
|
75
87
|
// cssModules.push(...options.vite?.config.vitrify.globalCss)
|
|
76
88
|
const matchedModules = componentsModules(cssModules, vite);
|
|
77
|
-
const css = collectCss(
|
|
89
|
+
const css = collectCss({
|
|
90
|
+
mods: matchedModules
|
|
91
|
+
});
|
|
78
92
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
|
|
79
93
|
const html = template
|
|
80
94
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fastify from 'fastify';
|
|
2
|
-
export const createApp = ({ onSetup, appDir, baseUrl, onRendered,
|
|
2
|
+
export const createApp = ({ onSetup, appDir, baseUrl, onRendered, fastifyPlugin, vitrifyDir, mode }) => {
|
|
3
3
|
const app = fastify({
|
|
4
4
|
logger: true
|
|
5
5
|
});
|
|
6
|
-
app.register(
|
|
6
|
+
app.register(fastifyPlugin, {
|
|
7
7
|
baseUrl,
|
|
8
8
|
appDir,
|
|
9
9
|
onRendered,
|
|
@@ -9,7 +9,7 @@ export const componentsModules = (components, vite) => {
|
|
|
9
9
|
});
|
|
10
10
|
return matchedModules;
|
|
11
11
|
};
|
|
12
|
-
export const collectCss = (mods, styles = new Map(), checkedComponents = new Set()) => {
|
|
12
|
+
export const collectCss = ({ mods, styles = new Map(), checkedComponents = new Set() }) => {
|
|
13
13
|
for (const mod of mods) {
|
|
14
14
|
if ((mod.file?.endsWith('.scss') ||
|
|
15
15
|
mod.file?.endsWith('.css') ||
|
|
@@ -19,7 +19,11 @@ export const collectCss = (mods, styles = new Map(), checkedComponents = new Set
|
|
|
19
19
|
}
|
|
20
20
|
if (mod.importedModules.size > 0 && !checkedComponents.has(mod.id)) {
|
|
21
21
|
checkedComponents.add(mod.id);
|
|
22
|
-
collectCss(
|
|
22
|
+
collectCss({
|
|
23
|
+
mods: mod.importedModules,
|
|
24
|
+
styles,
|
|
25
|
+
checkedComponents
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
let result = '';
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { readFileSync } from 'fs';
|
|
|
8
8
|
import builtinModules from 'builtin-modules';
|
|
9
9
|
import { resolve } from 'import-meta-resolve';
|
|
10
10
|
import { getPkgJsonDir } from './app-urls.js';
|
|
11
|
-
const
|
|
11
|
+
const internalServerModules = [
|
|
12
12
|
// 'fs',
|
|
13
13
|
// 'path',
|
|
14
14
|
// 'url',
|
|
@@ -19,25 +19,46 @@ const serverModules = [
|
|
|
19
19
|
'node:url',
|
|
20
20
|
'node:util',
|
|
21
21
|
'node:fs',
|
|
22
|
+
'node:process',
|
|
22
23
|
'vitrify',
|
|
24
|
+
'vitrify/dev',
|
|
25
|
+
// 'import-meta-resolve',
|
|
23
26
|
'vite',
|
|
24
27
|
'fastify',
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'@fastify/
|
|
32
|
-
'@fastify/
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
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'
|
|
36
42
|
];
|
|
37
43
|
const configPluginMap = {
|
|
38
44
|
quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
39
45
|
};
|
|
40
|
-
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
|
+
};
|
|
41
62
|
export const VIRTUAL_MODULES = [
|
|
42
63
|
'virtual:vitrify-hooks',
|
|
43
64
|
'virtual:global-css',
|
|
@@ -91,7 +112,7 @@ async function bundleConfigFile(fileName, isESM = false) {
|
|
|
91
112
|
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
92
113
|
};
|
|
93
114
|
}
|
|
94
|
-
export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
|
|
115
|
+
export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
|
|
95
116
|
const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
|
|
96
117
|
if (!appDir) {
|
|
97
118
|
appDir = getAppDir();
|
|
@@ -114,7 +135,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
114
135
|
const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir).pathname);
|
|
115
136
|
fs.writeFileSync(configPath + '.js', bundledConfig.code);
|
|
116
137
|
vitrifyConfig = (await import(configPath + '.js')).default;
|
|
117
|
-
|
|
138
|
+
fs.unlinkSync(configPath + '.js');
|
|
118
139
|
}
|
|
119
140
|
else {
|
|
120
141
|
vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
|
|
@@ -173,6 +194,12 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
173
194
|
let staticImports;
|
|
174
195
|
let sassVariables;
|
|
175
196
|
let additionalData;
|
|
197
|
+
let serverModules = internalServerModules;
|
|
198
|
+
if (vitrifyConfig.vitrify?.ssr?.serverModules)
|
|
199
|
+
serverModules = [
|
|
200
|
+
...serverModules,
|
|
201
|
+
...vitrifyConfig.vitrify.ssr.serverModules
|
|
202
|
+
];
|
|
176
203
|
const plugins = [
|
|
177
204
|
vuePlugin({
|
|
178
205
|
compiler: await import('vue/compiler-sfc'),
|
|
@@ -345,13 +372,17 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
345
372
|
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
346
373
|
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
347
374
|
];
|
|
375
|
+
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
376
|
+
alias.push(...vitrifyConfig.vitrify.dev.alias);
|
|
348
377
|
if (command === 'test')
|
|
349
378
|
alias.push({
|
|
350
379
|
find: 'vitest',
|
|
351
380
|
replacement: new URL(await resolve('vitest', cliDir.href)).pathname
|
|
352
381
|
});
|
|
353
|
-
let rollupOptions;
|
|
354
|
-
let noExternal = [
|
|
382
|
+
let rollupOptions = {};
|
|
383
|
+
let noExternal = [
|
|
384
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
385
|
+
];
|
|
355
386
|
const external = [...builtinModules, ...serverModules];
|
|
356
387
|
if (ssr === 'server') {
|
|
357
388
|
rollupOptions = {
|
|
@@ -365,17 +396,16 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
365
396
|
minifyInternalExports: false,
|
|
366
397
|
entryFileNames: '[name].mjs',
|
|
367
398
|
chunkFileNames: '[name].mjs',
|
|
368
|
-
|
|
369
|
-
manualChunks
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
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
|
+
// }
|
|
379
409
|
}
|
|
380
410
|
};
|
|
381
411
|
// Create a SSR bundle
|
|
@@ -392,17 +422,16 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
392
422
|
minifyInternalExports: false,
|
|
393
423
|
entryFileNames: '[name].mjs',
|
|
394
424
|
chunkFileNames: '[name].mjs',
|
|
395
|
-
|
|
396
|
-
manualChunks
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
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
|
+
// }
|
|
406
435
|
}
|
|
407
436
|
};
|
|
408
437
|
// Create a SSR bundle
|
|
@@ -412,15 +441,24 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
412
441
|
}
|
|
413
442
|
else {
|
|
414
443
|
rollupOptions = {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
+
}
|
|
419
456
|
};
|
|
420
457
|
}
|
|
421
458
|
const config = {
|
|
422
459
|
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
423
460
|
publicDir: publicDir.pathname,
|
|
461
|
+
base,
|
|
424
462
|
envDir: appDir.pathname,
|
|
425
463
|
vitrify: {
|
|
426
464
|
productName,
|
|
@@ -437,11 +475,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
437
475
|
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
438
476
|
},
|
|
439
477
|
resolve: {
|
|
440
|
-
|
|
441
|
-
// dedupe: [
|
|
442
|
-
// 'vue',
|
|
443
|
-
// 'vue-router'
|
|
444
|
-
// ],
|
|
478
|
+
dedupe: ['vue', 'vue-router'],
|
|
445
479
|
alias
|
|
446
480
|
},
|
|
447
481
|
build: {
|
|
@@ -483,8 +517,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
483
517
|
noExternal
|
|
484
518
|
},
|
|
485
519
|
define: {
|
|
486
|
-
__BASE_URL__: `'
|
|
520
|
+
__BASE_URL__: `'${base}'`
|
|
487
521
|
}
|
|
488
522
|
};
|
|
489
523
|
return mergeConfig(config, vitrifyConfig);
|
|
490
524
|
};
|
|
525
|
+
export const vitrifyDir = new URL('..', import.meta.url);
|
package/dist/plugins/quasar.js
CHANGED
|
@@ -37,6 +37,19 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
37
37
|
Components({
|
|
38
38
|
resolvers: [QuasarResolver()]
|
|
39
39
|
}),
|
|
40
|
+
{
|
|
41
|
+
name: 'vite-plugin-quasar-transform',
|
|
42
|
+
enforce: 'pre',
|
|
43
|
+
transform: (code, id, options) => {
|
|
44
|
+
const { ssr } = options || {};
|
|
45
|
+
code = code
|
|
46
|
+
.replaceAll('__QUASAR_SSR__', ssr ? ssr.toString() : 'false')
|
|
47
|
+
.replaceAll('__QUASAR_SSR_SERVER__', 'import.meta.env.SSR')
|
|
48
|
+
.replaceAll('__QUASAR_SSR_CLIENT__', '!import.meta.env.SSR')
|
|
49
|
+
.replaceAll('__QUASAR_SSR_PWA__', pwa ? '!import.meta.env.SSR' : 'false');
|
|
50
|
+
return code;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
40
53
|
{
|
|
41
54
|
name: 'vite-plugin-quasar-setup',
|
|
42
55
|
enforce: 'pre',
|
|
@@ -154,11 +167,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
154
167
|
},
|
|
155
168
|
define: {
|
|
156
169
|
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
157
|
-
__QUASAR_VERSION__: `'${version}'
|
|
158
|
-
__QUASAR_SSR__: !!ssr,
|
|
159
|
-
__QUASAR_SSR_SERVER__: ssr === 'server',
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
__QUASAR_VERSION__: `'${version}'`
|
|
171
|
+
// __QUASAR_SSR__: !!ssr,
|
|
172
|
+
// // __QUASAR_SSR_SERVER__: ssr === 'server',
|
|
173
|
+
// __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
|
|
174
|
+
// // __QUASAR_SSR_CLIENT__: ssr === 'client',
|
|
175
|
+
// __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
|
|
176
|
+
// // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
|
|
177
|
+
// __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
|
|
162
178
|
},
|
|
163
179
|
ssr: {
|
|
164
180
|
noExternal: ['quasar']
|