vitrify 0.11.6 → 0.11.8
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 +4 -3
- package/dist/bin/cli.js +17 -16
- package/dist/bin/dev.js +6 -5
- package/dist/bin/test.js +3 -2
- package/dist/frameworks/vue/fastify-csr-plugin.js +2 -1
- package/dist/frameworks/vue/fastify-ssr-plugin.js +5 -40
- package/dist/frameworks/vue/prerender.js +2 -3
- package/dist/index.js +27 -41
- package/dist/plugins/quasar.js +3 -2
- package/dist/types/index.d.ts +5 -5
- package/dist/types/vitrify-config.d.ts +8 -2
- package/package.json +1 -1
- package/src/node/app-urls.ts +4 -3
- package/src/node/bin/cli.ts +21 -16
- package/src/node/bin/dev.ts +6 -5
- package/src/node/bin/test.ts +3 -2
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +2 -2
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +10 -41
- package/src/node/frameworks/vue/prerender.ts +3 -4
- package/src/node/index.ts +53 -61
- package/src/node/plugins/quasar.ts +5 -5
- package/src/node/vitrify-config.ts +12 -4
package/dist/app-urls.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
// import { resolve } from 'import-meta-resolve'
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
export const resolve = (packageName, base, counter = 0) => {
|
|
4
5
|
const packageUrl = new URL(`./node_modules/${packageName}/`, base);
|
|
5
|
-
if (existsSync(packageUrl
|
|
6
|
+
if (existsSync(fileURLToPath(packageUrl))) {
|
|
6
7
|
return new URL('./', packageUrl);
|
|
7
8
|
}
|
|
8
9
|
if (counter < 10)
|
|
9
10
|
return resolve(packageName, new URL('../', base), counter + 1);
|
|
10
|
-
throw new Error(`Package ${packageName} not found in ${base
|
|
11
|
+
throw new Error(`Package ${packageName} not found in ${fileURLToPath(base)}.`);
|
|
11
12
|
};
|
|
12
13
|
export const getPkgJsonDir = (dir) => {
|
|
13
14
|
const pkgJsonPath = new URL('package.json', dir);
|
|
14
|
-
if (existsSync(pkgJsonPath
|
|
15
|
+
if (existsSync(fileURLToPath(pkgJsonPath))) {
|
|
15
16
|
return new URL('./', pkgJsonPath);
|
|
16
17
|
}
|
|
17
18
|
return getPkgJsonDir(new URL('..', dir));
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import cac from 'cac';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
import { getAppDir, parsePath } from '../app-urls.js';
|
|
4
5
|
import { printHttpServerUrls, exitLogs } from '../helpers/logger.js';
|
|
5
6
|
const cli = cac('vitrify');
|
|
@@ -37,47 +38,45 @@ cli
|
|
|
37
38
|
case 'csr':
|
|
38
39
|
await build({
|
|
39
40
|
...args,
|
|
40
|
-
outDir: new URL('csr/', baseOutDir)
|
|
41
|
+
outDir: fileURLToPath(new URL('csr/', baseOutDir))
|
|
41
42
|
});
|
|
42
43
|
break;
|
|
43
44
|
case 'fastify':
|
|
44
45
|
await build({
|
|
45
46
|
ssr: 'fastify',
|
|
46
47
|
...args,
|
|
47
|
-
outDir: new URL('server/', baseOutDir)
|
|
48
|
+
outDir: fileURLToPath(new URL('server/', baseOutDir))
|
|
48
49
|
});
|
|
49
50
|
break;
|
|
50
51
|
case 'ssr':
|
|
51
52
|
await build({
|
|
52
53
|
ssr: 'client',
|
|
53
54
|
...args,
|
|
54
|
-
outDir: new URL('ssr/client/', baseOutDir)
|
|
55
|
+
outDir: fileURLToPath(new URL('ssr/client/', baseOutDir))
|
|
55
56
|
});
|
|
56
57
|
await build({
|
|
57
58
|
ssr: 'server',
|
|
58
59
|
...args,
|
|
59
|
-
outDir: new URL('ssr/server/', baseOutDir)
|
|
60
|
+
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
60
61
|
});
|
|
61
62
|
break;
|
|
62
63
|
case 'ssg':
|
|
63
64
|
await build({
|
|
64
65
|
ssr: 'client',
|
|
65
66
|
...args,
|
|
66
|
-
outDir: new URL('static/', baseOutDir)
|
|
67
|
+
outDir: fileURLToPath(new URL('static/', baseOutDir))
|
|
67
68
|
});
|
|
68
69
|
await build({
|
|
69
70
|
ssr: 'server',
|
|
70
71
|
...args,
|
|
71
|
-
outDir: new URL('ssr/server/', baseOutDir)
|
|
72
|
+
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
72
73
|
});
|
|
73
|
-
({ prerender, onRendered } = await import(new URL('ssr/server/prerender.mjs', baseOutDir)
|
|
74
|
+
({ prerender, onRendered } = await import(fileURLToPath(new URL('ssr/server/prerender.mjs', baseOutDir))));
|
|
74
75
|
prerender({
|
|
75
|
-
outDir: new URL('static/', baseOutDir)
|
|
76
|
-
templatePath: new URL('static/index.html', baseOutDir)
|
|
77
|
-
manifestPath: new URL('static/ssr-manifest.json', baseOutDir)
|
|
78
|
-
|
|
79
|
-
entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
80
|
-
.pathname,
|
|
76
|
+
outDir: fileURLToPath(new URL('static/', baseOutDir)),
|
|
77
|
+
templatePath: fileURLToPath(new URL('static/index.html', baseOutDir)),
|
|
78
|
+
manifestPath: fileURLToPath(new URL('static/ssr-manifest.json', baseOutDir)),
|
|
79
|
+
entryServerPath: fileURLToPath(new URL('ssr/server/entry-server.mjs', baseOutDir)),
|
|
81
80
|
onRendered
|
|
82
81
|
});
|
|
83
82
|
break;
|
|
@@ -102,8 +101,10 @@ cli
|
|
|
102
101
|
const { createServer } = await import('./dev.js');
|
|
103
102
|
const cwd = (await import('../app-urls.js')).getCwd();
|
|
104
103
|
let app;
|
|
105
|
-
const
|
|
106
|
-
|
|
104
|
+
const appURL = parsePath(options.app, cwd);
|
|
105
|
+
let appPath;
|
|
106
|
+
if (appURL) {
|
|
107
|
+
appPath = fileURLToPath(appURL);
|
|
107
108
|
app = await import(appPath);
|
|
108
109
|
}
|
|
109
110
|
switch (options.mode) {
|
|
@@ -158,7 +159,7 @@ cli.command('test').action(async (options) => {
|
|
|
158
159
|
cli.command('run <file>').action(async (file, options) => {
|
|
159
160
|
const { run } = await import('./run.js');
|
|
160
161
|
const filePath = new URL(file, `file://${process.cwd()}/`);
|
|
161
|
-
await run(filePath
|
|
162
|
+
await run(fileURLToPath(filePath));
|
|
162
163
|
});
|
|
163
164
|
// Default
|
|
164
165
|
cli.command('').action((command, options) => {
|
package/dist/bin/dev.js
CHANGED
|
@@ -4,6 +4,7 @@ import fastify from 'fastify';
|
|
|
4
4
|
import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
|
|
5
5
|
import isPortReachable from 'is-port-reachable';
|
|
6
6
|
import { exitLogs } from '../helpers/logger.js';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
7
8
|
const getFirstOpenPort = async (portNumber) => {
|
|
8
9
|
if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
|
|
9
10
|
return portNumber;
|
|
@@ -54,9 +55,9 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
|
|
|
54
55
|
strict: false,
|
|
55
56
|
allow: [
|
|
56
57
|
searchForWorkspaceRoot(process.cwd()),
|
|
57
|
-
searchForWorkspaceRoot(appDir
|
|
58
|
-
searchForWorkspaceRoot(cliDir
|
|
59
|
-
appDir
|
|
58
|
+
searchForWorkspaceRoot(fileURLToPath(appDir)),
|
|
59
|
+
searchForWorkspaceRoot(fileURLToPath(cliDir)),
|
|
60
|
+
fileURLToPath(appDir)
|
|
60
61
|
]
|
|
61
62
|
},
|
|
62
63
|
watch: {
|
|
@@ -97,8 +98,8 @@ ssr, framework = 'vue', host, appDir, publicDir }) {
|
|
|
97
98
|
console.log(`Development mode: ${ssr ? ssr : 'csr'}`);
|
|
98
99
|
if (ssr) {
|
|
99
100
|
const entryUrl = ssr === 'fastify'
|
|
100
|
-
? new URL('src/vite/fastify/entry.ts', cliDir)
|
|
101
|
-
: new URL(`src/vite/${framework}/ssr/app.ts`, cliDir)
|
|
101
|
+
? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
|
|
102
|
+
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir));
|
|
102
103
|
({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl));
|
|
103
104
|
const app = fastify({
|
|
104
105
|
logger: {
|
package/dist/bin/test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { startVitest } from 'vitest/node';
|
|
2
2
|
import { baseConfig } from '../index.js';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
export async function test(opts) {
|
|
4
5
|
const config = await baseConfig({
|
|
5
6
|
appDir: opts.appDir,
|
|
@@ -7,8 +8,8 @@ export async function test(opts) {
|
|
|
7
8
|
mode: 'development'
|
|
8
9
|
});
|
|
9
10
|
await startVitest('test', [], {
|
|
10
|
-
root: opts.appDir
|
|
11
|
-
dir: opts.appDir
|
|
11
|
+
root: fileURLToPath(opts.appDir),
|
|
12
|
+
dir: fileURLToPath(opts.appDir),
|
|
12
13
|
globals: true,
|
|
13
14
|
environment: 'happy-dom'
|
|
14
15
|
}, config);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fastifyStatic from '@fastify/static';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
2
3
|
const fastifyCsrPlugin = async (fastify, options, done) => {
|
|
3
4
|
options.vitrifyDir =
|
|
4
5
|
options.vitrifyDir || (await import('vitrify')).vitrifyDir;
|
|
@@ -28,7 +29,7 @@ const fastifyCsrPlugin = async (fastify, options, done) => {
|
|
|
28
29
|
else {
|
|
29
30
|
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
30
31
|
fastify.register(fastifyStatic, {
|
|
31
|
-
root: new URL('./dist/csr', options.appDir)
|
|
32
|
+
root: fileURLToPath(new URL('./dist/csr', options.appDir)),
|
|
32
33
|
wildcard: false,
|
|
33
34
|
index: false,
|
|
34
35
|
prefix: options.baseUrl
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fastifyStatic from '@fastify/static';
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
import { addOrReplaceAppDiv, appendToBody, appendToHead } from '../../helpers/utils.js';
|
|
4
5
|
const fastifySsrPlugin = async (fastify, options, done) => {
|
|
5
6
|
options.baseUrl = options.baseUrl || '/';
|
|
@@ -12,11 +13,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
12
13
|
options.vitrifyDir =
|
|
13
14
|
options.vitrifyDir || (await import('vitrify')).vitrifyDir;
|
|
14
15
|
const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir);
|
|
15
|
-
// if (!options.vitrifyDir)
|
|
16
|
-
// throw new Error('Option vitrifyDir cannot be undefined')
|
|
17
|
-
// if (!options.vite) throw new Error('Option vite cannot be undefined')
|
|
18
|
-
// const { resolve } = await import('import-meta-resolve')
|
|
19
|
-
// const cliDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
20
16
|
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
21
17
|
const { createVitrifyDevServer } = await import('vitrify/dev');
|
|
22
18
|
const vite = await createVitrifyDevServer({
|
|
@@ -26,37 +22,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
26
22
|
base: options.baseUrl,
|
|
27
23
|
host: options.host
|
|
28
24
|
});
|
|
29
|
-
// const { createServer, searchForWorkspaceRoot } = await import('vite')
|
|
30
|
-
// const { baseConfig } = await import('vitrify')
|
|
31
|
-
// const cliDir = options.vitrifyDir
|
|
32
|
-
// const config = await baseConfig({
|
|
33
|
-
// ssr: 'server',
|
|
34
|
-
// command: 'dev',
|
|
35
|
-
// mode: 'development',
|
|
36
|
-
// appDir: options.appDir,
|
|
37
|
-
// publicDir: options.publicDir || new URL('public', options.appDir)
|
|
38
|
-
// })
|
|
39
|
-
// config.server = {
|
|
40
|
-
// middlewareMode: true,
|
|
41
|
-
// fs: {
|
|
42
|
-
// allow: [
|
|
43
|
-
// searchForWorkspaceRoot(process.cwd()),
|
|
44
|
-
// searchForWorkspaceRoot(options.appDir.pathname),
|
|
45
|
-
// searchForWorkspaceRoot(cliDir.pathname)
|
|
46
|
-
// // appDir.pathname,
|
|
47
|
-
// ]
|
|
48
|
-
// },
|
|
49
|
-
// watch: {
|
|
50
|
-
// // During tests we edit the files too fast and sometimes chokidar
|
|
51
|
-
// // misses change events, so enforce polling for consistency
|
|
52
|
-
// usePolling: true,
|
|
53
|
-
// interval: 100
|
|
54
|
-
// }
|
|
55
|
-
// }
|
|
56
|
-
// const vite = await createServer({
|
|
57
|
-
// configFile: false,
|
|
58
|
-
// ...config
|
|
59
|
-
// })
|
|
60
25
|
if (!('use' in fastify)) {
|
|
61
26
|
const middie = (await import('@fastify/middie')).default;
|
|
62
27
|
// @ts-ignore
|
|
@@ -74,7 +39,7 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
74
39
|
};
|
|
75
40
|
let template = readFileSync(new URL('index.html', frameworkDir)).toString();
|
|
76
41
|
template = await vite.transformIndexHtml(url, template);
|
|
77
|
-
const entryUrl = new URL('ssr/entry-server.ts', frameworkDir)
|
|
42
|
+
const entryUrl = fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir));
|
|
78
43
|
const render = (await vite.ssrLoadModule(entryUrl)).render;
|
|
79
44
|
let manifest;
|
|
80
45
|
// TODO: https://github.com/vitejs/vite/issues/2282
|
|
@@ -133,7 +98,7 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
133
98
|
else {
|
|
134
99
|
options.appDir = options.appDir || new URL('../../..', import.meta.url);
|
|
135
100
|
fastify.register(fastifyStatic, {
|
|
136
|
-
root: new URL('./dist/ssr/client', options.appDir)
|
|
101
|
+
root: fileURLToPath(new URL('./dist/ssr/client', options.appDir)),
|
|
137
102
|
wildcard: false,
|
|
138
103
|
index: false,
|
|
139
104
|
prefix: options.baseUrl
|
|
@@ -146,9 +111,9 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
146
111
|
res,
|
|
147
112
|
provide
|
|
148
113
|
};
|
|
149
|
-
const template = readFileSync(new URL('./dist/ssr/client/index.html', options.appDir)
|
|
114
|
+
const template = readFileSync(fileURLToPath(new URL('./dist/ssr/client/index.html', options.appDir))).toString();
|
|
150
115
|
const manifest = JSON.parse(readFileSync(new URL('./dist/ssr/client/ssr-manifest.json', options.appDir)).toString());
|
|
151
|
-
const render = (await import(new URL('./dist/ssr/server/entry-server.mjs', options.appDir)
|
|
116
|
+
const render = (await import(fileURLToPath(new URL('./dist/ssr/server/entry-server.mjs', options.appDir)))).render;
|
|
152
117
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
|
|
153
118
|
if (!ssrContext.initialState)
|
|
154
119
|
ssrContext.initialState = {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js';
|
|
3
|
-
import { appendToHead } from '../../helpers/utils.js';
|
|
3
|
+
import { appendToHead, addOrReplaceAppDiv } from '../../helpers/utils.js';
|
|
4
4
|
export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath, onRendered }) => {
|
|
5
5
|
const promises = [];
|
|
6
6
|
const template = (await fs.readFile(templatePath)).toString();
|
|
@@ -23,9 +23,8 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
|
|
|
23
23
|
res: {}
|
|
24
24
|
};
|
|
25
25
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
|
|
26
|
-
let html =
|
|
26
|
+
let html = addOrReplaceAppDiv(appHtml, template);
|
|
27
27
|
html = appendToHead(preloadLinks, html);
|
|
28
|
-
// html = appendToBody(preloadLinks, html)
|
|
29
28
|
if (onRendered?.length) {
|
|
30
29
|
for (const ssrFunction of onRendered) {
|
|
31
30
|
html = ssrFunction(html, ssrContext);
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { pathToFileURL } from 'url';
|
|
|
8
8
|
import { readFileSync } from 'fs';
|
|
9
9
|
import builtinModules from 'builtin-modules';
|
|
10
10
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
11
12
|
import { resolve } from './app-urls.js';
|
|
12
13
|
import { addOrReplaceTitle, appendToBody } from './helpers/utils.js';
|
|
13
14
|
import Components from 'unplugin-vue-components/vite';
|
|
@@ -156,20 +157,17 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
156
157
|
const fastifyDir = new URL('fastify/', cliViteDir);
|
|
157
158
|
if (!publicDir)
|
|
158
159
|
publicDir = new URL('public/', appDir);
|
|
159
|
-
/**
|
|
160
|
-
* TODO:Perform some manual check if command is run inside a Quasar Project
|
|
161
|
-
*/
|
|
162
160
|
let vitrifyConfig;
|
|
163
161
|
try {
|
|
164
|
-
if (fs.existsSync(new URL('vitrify.config.ts', appDir)
|
|
165
|
-
const configPath = new URL('vitrify.config.ts', appDir)
|
|
166
|
-
const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir)
|
|
162
|
+
if (fs.existsSync(fileURLToPath(new URL('vitrify.config.ts', appDir)))) {
|
|
163
|
+
const configPath = fileURLToPath(new URL('vitrify.config.ts', appDir));
|
|
164
|
+
const bundledConfig = await bundleConfigFile(fileURLToPath(new URL('vitrify.config.ts', appDir)));
|
|
167
165
|
fs.writeFileSync(configPath + '.js', bundledConfig.code);
|
|
168
166
|
vitrifyConfig = (await import(configPath + '.js')).default;
|
|
169
167
|
fs.unlinkSync(configPath + '.js');
|
|
170
168
|
}
|
|
171
169
|
else {
|
|
172
|
-
vitrifyConfig = (await import(new URL('vitrify.config.js', appDir)
|
|
170
|
+
vitrifyConfig = (await import(fileURLToPath(new URL('vitrify.config.js', appDir)))).default;
|
|
173
171
|
}
|
|
174
172
|
if (typeof vitrifyConfig === 'function')
|
|
175
173
|
vitrifyConfig = await vitrifyConfig({ mode, command });
|
|
@@ -186,7 +184,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
186
184
|
const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
|
|
187
185
|
await (async () => {
|
|
188
186
|
for (const val of localPackages) {
|
|
189
|
-
const pkg = resolvePackageData(val, appDir
|
|
187
|
+
const pkg = resolvePackageData(val, fileURLToPath(appDir));
|
|
190
188
|
if (pkg)
|
|
191
189
|
packageUrls[val] = new URL(`file://${pkg.dir}/`);
|
|
192
190
|
}
|
|
@@ -200,7 +198,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
200
198
|
if (!productName) {
|
|
201
199
|
try {
|
|
202
200
|
;
|
|
203
|
-
({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir)
|
|
201
|
+
({ productName } = JSON.parse(readFileSync(fileURLToPath(new URL('package.json', appDir)), {
|
|
204
202
|
encoding: 'utf-8'
|
|
205
203
|
})));
|
|
206
204
|
if (!productName)
|
|
@@ -233,7 +231,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
233
231
|
let globalCss = [];
|
|
234
232
|
let staticImports;
|
|
235
233
|
let sassVariables;
|
|
236
|
-
let additionalData;
|
|
237
234
|
let globalSass;
|
|
238
235
|
let serverModules = internalServerModules;
|
|
239
236
|
if (vitrifyConfig.vitrify?.ssr?.serverModules)
|
|
@@ -280,7 +277,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
280
277
|
staticImports = config.vitrify?.staticImports || {};
|
|
281
278
|
sassVariables = config.vitrify?.sass?.variables || {};
|
|
282
279
|
globalSass = config.vitrify?.sass?.global || [];
|
|
283
|
-
additionalData = config.vitrify?.sass?.additionalData || [];
|
|
284
280
|
return;
|
|
285
281
|
},
|
|
286
282
|
configureServer(server) {
|
|
@@ -332,13 +328,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
332
328
|
export const onSetup = []
|
|
333
329
|
${onSetupFiles
|
|
334
330
|
.map((url, index) => {
|
|
335
|
-
const varName = url
|
|
331
|
+
const varName = fileURLToPath(url)
|
|
336
332
|
.replaceAll('/', '')
|
|
337
333
|
.replaceAll('.', '')
|
|
338
334
|
.replaceAll('-', '')
|
|
339
335
|
.replaceAll('_', '')
|
|
340
336
|
.replaceAll('+', '');
|
|
341
|
-
return `import ${varName} from '${url
|
|
337
|
+
return `import ${varName} from '${fileURLToPath(url)}'; onSetup.push(${varName})`;
|
|
342
338
|
})
|
|
343
339
|
.join('\n')}`;
|
|
344
340
|
}
|
|
@@ -378,16 +374,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
378
374
|
plugins.unshift({
|
|
379
375
|
name: 'html-transform',
|
|
380
376
|
enforce: 'pre',
|
|
381
|
-
// transform: (code, id) => {
|
|
382
|
-
// if (id.endsWith('App.vue')) {
|
|
383
|
-
// code =
|
|
384
|
-
// code +
|
|
385
|
-
// `<style lang="sass">
|
|
386
|
-
// // do not remove, required for additionalData import
|
|
387
|
-
// </style>`
|
|
388
|
-
// }
|
|
389
|
-
// return code
|
|
390
|
-
// },
|
|
391
377
|
transformIndexHtml: {
|
|
392
378
|
enforce: 'pre',
|
|
393
379
|
transform: (html) => {
|
|
@@ -396,13 +382,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
396
382
|
case 'ssg':
|
|
397
383
|
case 'server':
|
|
398
384
|
case 'client':
|
|
399
|
-
entry = new URL('ssr/entry-client.ts', frameworkDir)
|
|
385
|
+
entry = fileURLToPath(new URL('ssr/entry-client.ts', frameworkDir));
|
|
400
386
|
break;
|
|
401
387
|
case 'fastify':
|
|
402
|
-
entry = new URL('entry.ts', fastifyDir)
|
|
388
|
+
entry = fileURLToPath(new URL('entry.ts', fastifyDir));
|
|
403
389
|
break;
|
|
404
390
|
default:
|
|
405
|
-
entry = new URL('csr/entry.ts', frameworkDir)
|
|
391
|
+
entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir));
|
|
406
392
|
}
|
|
407
393
|
const entryScript = `<script type="module" src="${entry}"></script>`;
|
|
408
394
|
// html = html.replace('<!--entry-script-->', entryScript)
|
|
@@ -435,22 +421,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
435
421
|
plugins.push(visualizer());
|
|
436
422
|
}
|
|
437
423
|
const alias = [
|
|
438
|
-
{ find: 'src', replacement: srcDir
|
|
439
|
-
{ find: 'app', replacement: appDir
|
|
440
|
-
{ find: 'cwd', replacement: cwd
|
|
441
|
-
{ find: 'boot', replacement: new URL('boot/', srcDir)
|
|
442
|
-
{ find: 'assets', replacement: new URL('assets/', srcDir)
|
|
424
|
+
{ find: 'src', replacement: fileURLToPath(srcDir) },
|
|
425
|
+
{ find: 'app', replacement: fileURLToPath(appDir) },
|
|
426
|
+
{ find: 'cwd', replacement: fileURLToPath(cwd) },
|
|
427
|
+
{ find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
|
|
428
|
+
{ find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
|
|
443
429
|
// ...Object.entries(packageUrls).map(([key, value]) => ({
|
|
444
430
|
// find: key,
|
|
445
431
|
// replacement: value.pathname
|
|
446
432
|
// }))
|
|
447
433
|
{
|
|
448
434
|
find: new RegExp('^vue$'),
|
|
449
|
-
replacement: new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue'])
|
|
435
|
+
replacement: fileURLToPath(new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']))
|
|
450
436
|
},
|
|
451
437
|
{
|
|
452
438
|
find: new RegExp('^vue-router$'),
|
|
453
|
-
replacement: new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router'])
|
|
439
|
+
replacement: fileURLToPath(new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']))
|
|
454
440
|
}
|
|
455
441
|
];
|
|
456
442
|
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
@@ -458,7 +444,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
458
444
|
if (command === 'test')
|
|
459
445
|
alias.push({
|
|
460
446
|
find: 'vitest',
|
|
461
|
-
replacement: new URL(await resolve('vitest', cliDir))
|
|
447
|
+
replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
|
|
462
448
|
});
|
|
463
449
|
let rollupOptions = {};
|
|
464
450
|
let noExternal = [
|
|
@@ -469,9 +455,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
469
455
|
rollupOptions = {
|
|
470
456
|
...rollupOptions,
|
|
471
457
|
input: [
|
|
472
|
-
new URL('ssr/entry-server.ts', frameworkDir)
|
|
473
|
-
new URL('ssr/prerender.ts', frameworkDir)
|
|
474
|
-
new URL('ssr/server.ts', frameworkDir)
|
|
458
|
+
fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir)),
|
|
459
|
+
fileURLToPath(new URL('ssr/prerender.ts', frameworkDir)),
|
|
460
|
+
fileURLToPath(new URL('ssr/server.ts', frameworkDir))
|
|
475
461
|
],
|
|
476
462
|
external,
|
|
477
463
|
output: {
|
|
@@ -490,7 +476,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
490
476
|
else if (ssr === 'fastify') {
|
|
491
477
|
rollupOptions = {
|
|
492
478
|
...rollupOptions,
|
|
493
|
-
input: [new URL('server.ts', fastifyDir)
|
|
479
|
+
input: [fileURLToPath(new URL('server.ts', fastifyDir))],
|
|
494
480
|
external,
|
|
495
481
|
output: {
|
|
496
482
|
minifyInternalExports: false,
|
|
@@ -519,10 +505,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
519
505
|
};
|
|
520
506
|
}
|
|
521
507
|
const config = {
|
|
522
|
-
root: appDir
|
|
523
|
-
publicDir: publicDir
|
|
508
|
+
root: fileURLToPath(appDir),
|
|
509
|
+
publicDir: fileURLToPath(publicDir),
|
|
524
510
|
base,
|
|
525
|
-
envDir: appDir
|
|
511
|
+
envDir: fileURLToPath(appDir),
|
|
526
512
|
vitrify: {
|
|
527
513
|
productName,
|
|
528
514
|
urls: {
|
package/dist/plugins/quasar.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolvePackageData } from 'vite';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
2
3
|
export const injectSsrContext = (html, ssrContext) => html
|
|
3
4
|
.replace(/(<html[^>]*)(>)/i, (found, start, end) => {
|
|
4
5
|
let matches;
|
|
@@ -51,7 +52,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
51
52
|
// const localPackages: string[] = []
|
|
52
53
|
await (async () => {
|
|
53
54
|
for (const val of localPackages) {
|
|
54
|
-
const pkg = resolvePackageData(val, config.vitrify.urls.app
|
|
55
|
+
const pkg = resolvePackageData(val, fileURLToPath(config.vitrify.urls.app));
|
|
55
56
|
if (pkg)
|
|
56
57
|
urls.packages[val] = new URL(`file://${pkg.dir}/`);
|
|
57
58
|
}
|
|
@@ -121,7 +122,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
121
122
|
alias: [
|
|
122
123
|
{
|
|
123
124
|
find: 'quasar/src/',
|
|
124
|
-
replacement: new URL('./src/', config.vitrify.urls.packages.quasar)
|
|
125
|
+
replacement: fileURLToPath(new URL('./src/', config.vitrify.urls.packages.quasar))
|
|
125
126
|
}
|
|
126
127
|
]
|
|
127
128
|
},
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { InlineConfig } from 'vite';
|
|
2
|
-
import type { BootFunction, VitrifyConfig } from './vitrify-config.js';
|
|
2
|
+
import type { BootFunction, VitrifyConfig, VitrifyConfigAsync, VitrifyCommands, VitrifyModes, VitrifyUIFrameworks, VitrifySSRModes } from './vitrify-config.js';
|
|
3
3
|
import type { VitrifyContext } from './bin/run.js';
|
|
4
4
|
import type { VitrifyPlugin } from './plugins/index.js';
|
|
5
5
|
export declare const VIRTUAL_MODULES: string[];
|
|
6
6
|
export declare const baseConfig: ({ ssr, appDir, publicDir, base, command, mode, framework, pwa, debug, productName }: {
|
|
7
|
-
ssr?:
|
|
7
|
+
ssr?: VitrifySSRModes | undefined;
|
|
8
8
|
appDir?: URL | undefined;
|
|
9
9
|
publicDir?: URL | undefined;
|
|
10
10
|
base?: string | undefined;
|
|
11
|
-
command?:
|
|
12
|
-
mode?:
|
|
11
|
+
command?: VitrifyCommands | undefined;
|
|
12
|
+
mode?: VitrifyModes | undefined;
|
|
13
13
|
framework?: "vue" | undefined;
|
|
14
14
|
pwa?: boolean | undefined;
|
|
15
15
|
debug?: boolean | undefined;
|
|
@@ -17,4 +17,4 @@ export declare const baseConfig: ({ ssr, appDir, publicDir, base, command, mode,
|
|
|
17
17
|
}) => Promise<InlineConfig>;
|
|
18
18
|
export declare const vitrifyDir: URL;
|
|
19
19
|
export { prerender } from './frameworks/vue/prerender.js';
|
|
20
|
-
export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction };
|
|
20
|
+
export type { VitrifyConfig, VitrifyConfigAsync, VitrifyPlugin, VitrifyContext, BootFunction };
|
|
@@ -51,7 +51,6 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
51
51
|
*/
|
|
52
52
|
sass?: {
|
|
53
53
|
variables?: Record<string, string>;
|
|
54
|
-
additionalData?: string[];
|
|
55
54
|
global?: string[];
|
|
56
55
|
};
|
|
57
56
|
/**
|
|
@@ -88,5 +87,12 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
88
87
|
};
|
|
89
88
|
quasar?: QuasarConf;
|
|
90
89
|
}
|
|
91
|
-
export type
|
|
90
|
+
export type VitrifyCommands = 'build' | 'dev' | 'test';
|
|
91
|
+
export type VitrifyModes = 'production' | 'development';
|
|
92
|
+
export type VitrifyUIFrameworks = 'vue';
|
|
93
|
+
export type VitrifySSRModes = 'client' | 'server' | 'ssg' | 'fastify';
|
|
94
|
+
export type VitrifyConfigAsync = ({ mode, command }: {
|
|
95
|
+
mode: VitrifyModes;
|
|
96
|
+
command: VitrifyCommands;
|
|
97
|
+
}) => Promise<VitrifyConfig>;
|
|
92
98
|
export declare const defineConfig: (config: VitrifyConfig) => VitrifyConfig;
|
package/package.json
CHANGED
package/src/node/app-urls.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
// import { resolve } from 'import-meta-resolve'
|
|
2
2
|
import { existsSync } from 'fs'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
3
4
|
|
|
4
5
|
export const resolve = (packageName: string, base: URL, counter = 0): URL => {
|
|
5
6
|
const packageUrl = new URL(`./node_modules/${packageName}/`, base)
|
|
6
|
-
if (existsSync(packageUrl
|
|
7
|
+
if (existsSync(fileURLToPath(packageUrl))) {
|
|
7
8
|
return new URL('./', packageUrl)
|
|
8
9
|
}
|
|
9
10
|
if (counter < 10)
|
|
10
11
|
return resolve(packageName, new URL('../', base), counter + 1)
|
|
11
|
-
throw new Error(`Package ${packageName} not found in ${base
|
|
12
|
+
throw new Error(`Package ${packageName} not found in ${fileURLToPath(base)}.`)
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export const getPkgJsonDir = (dir: URL): URL => {
|
|
15
16
|
const pkgJsonPath = new URL('package.json', dir)
|
|
16
|
-
if (existsSync(pkgJsonPath
|
|
17
|
+
if (existsSync(fileURLToPath(pkgJsonPath))) {
|
|
17
18
|
return new URL('./', pkgJsonPath)
|
|
18
19
|
}
|
|
19
20
|
return getPkgJsonDir(new URL('..', dir))
|
package/src/node/bin/cli.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import cac from 'cac'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
3
4
|
import { getAppDir, parsePath } from '../app-urls.js'
|
|
4
5
|
import { printHttpServerUrls, exitLogs } from '../helpers/logger.js'
|
|
5
6
|
import type { ResolvedConfig } from 'vite'
|
|
@@ -48,50 +49,52 @@ cli
|
|
|
48
49
|
case 'csr':
|
|
49
50
|
await build({
|
|
50
51
|
...args,
|
|
51
|
-
outDir: new URL('csr/', baseOutDir)
|
|
52
|
+
outDir: fileURLToPath(new URL('csr/', baseOutDir))
|
|
52
53
|
})
|
|
53
54
|
break
|
|
54
55
|
case 'fastify':
|
|
55
56
|
await build({
|
|
56
57
|
ssr: 'fastify',
|
|
57
58
|
...args,
|
|
58
|
-
outDir: new URL('server/', baseOutDir)
|
|
59
|
+
outDir: fileURLToPath(new URL('server/', baseOutDir))
|
|
59
60
|
})
|
|
60
61
|
break
|
|
61
62
|
case 'ssr':
|
|
62
63
|
await build({
|
|
63
64
|
ssr: 'client',
|
|
64
65
|
...args,
|
|
65
|
-
outDir: new URL('ssr/client/', baseOutDir)
|
|
66
|
+
outDir: fileURLToPath(new URL('ssr/client/', baseOutDir))
|
|
66
67
|
})
|
|
67
68
|
await build({
|
|
68
69
|
ssr: 'server',
|
|
69
70
|
...args,
|
|
70
|
-
outDir: new URL('ssr/server/', baseOutDir)
|
|
71
|
+
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
71
72
|
})
|
|
72
73
|
break
|
|
73
74
|
case 'ssg':
|
|
74
75
|
await build({
|
|
75
76
|
ssr: 'client',
|
|
76
77
|
...args,
|
|
77
|
-
outDir: new URL('static/', baseOutDir)
|
|
78
|
+
outDir: fileURLToPath(new URL('static/', baseOutDir))
|
|
78
79
|
})
|
|
79
80
|
await build({
|
|
80
81
|
ssr: 'server',
|
|
81
82
|
...args,
|
|
82
|
-
outDir: new URL('ssr/server/', baseOutDir)
|
|
83
|
+
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
83
84
|
})
|
|
84
85
|
;({ prerender, onRendered } = await import(
|
|
85
|
-
new URL('ssr/server/prerender.mjs', baseOutDir)
|
|
86
|
+
fileURLToPath(new URL('ssr/server/prerender.mjs', baseOutDir))
|
|
86
87
|
))
|
|
87
88
|
|
|
88
89
|
prerender({
|
|
89
|
-
outDir: new URL('static/', baseOutDir)
|
|
90
|
-
templatePath: new URL('static/index.html', baseOutDir)
|
|
91
|
-
manifestPath:
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
outDir: fileURLToPath(new URL('static/', baseOutDir)),
|
|
91
|
+
templatePath: fileURLToPath(new URL('static/index.html', baseOutDir)),
|
|
92
|
+
manifestPath: fileURLToPath(
|
|
93
|
+
new URL('static/ssr-manifest.json', baseOutDir)
|
|
94
|
+
),
|
|
95
|
+
entryServerPath: fileURLToPath(
|
|
96
|
+
new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
97
|
+
),
|
|
95
98
|
onRendered
|
|
96
99
|
})
|
|
97
100
|
break
|
|
@@ -121,8 +124,10 @@ cli
|
|
|
121
124
|
const { createServer } = await import('./dev.js')
|
|
122
125
|
const cwd = (await import('../app-urls.js')).getCwd()
|
|
123
126
|
let app
|
|
124
|
-
const
|
|
125
|
-
|
|
127
|
+
const appURL = parsePath(options.app, cwd)
|
|
128
|
+
let appPath: string
|
|
129
|
+
if (appURL) {
|
|
130
|
+
appPath = fileURLToPath(appURL)
|
|
126
131
|
app = await import(appPath)
|
|
127
132
|
}
|
|
128
133
|
|
|
@@ -176,7 +181,7 @@ cli.command('test').action(async (options) => {
|
|
|
176
181
|
cli.command('run <file>').action(async (file, options) => {
|
|
177
182
|
const { run } = await import('./run.js')
|
|
178
183
|
const filePath = new URL(file, `file://${process.cwd()}/`)
|
|
179
|
-
await run(filePath
|
|
184
|
+
await run(fileURLToPath(filePath))
|
|
180
185
|
})
|
|
181
186
|
|
|
182
187
|
// Default
|
package/src/node/bin/dev.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
|
|
|
8
8
|
import type { OnRenderedHook, VitrifyConfig } from '../vitrify-config.js'
|
|
9
9
|
import isPortReachable from 'is-port-reachable'
|
|
10
10
|
import { exitLogs } from '../helpers/logger.js'
|
|
11
|
+
import { fileURLToPath } from 'url'
|
|
11
12
|
|
|
12
13
|
const getFirstOpenPort = async (portNumber: number): Promise<number> => {
|
|
13
14
|
if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
|
|
@@ -84,9 +85,9 @@ export async function createVitrifyDevServer({
|
|
|
84
85
|
strict: false, // https://github.com/vitejs/vite/issues/8175
|
|
85
86
|
allow: [
|
|
86
87
|
searchForWorkspaceRoot(process.cwd()),
|
|
87
|
-
searchForWorkspaceRoot(appDir
|
|
88
|
-
searchForWorkspaceRoot(cliDir
|
|
89
|
-
appDir
|
|
88
|
+
searchForWorkspaceRoot(fileURLToPath(appDir)),
|
|
89
|
+
searchForWorkspaceRoot(fileURLToPath(cliDir)),
|
|
90
|
+
fileURLToPath(appDir)
|
|
90
91
|
]
|
|
91
92
|
},
|
|
92
93
|
watch: {
|
|
@@ -154,8 +155,8 @@ export async function createServer({
|
|
|
154
155
|
if (ssr) {
|
|
155
156
|
const entryUrl =
|
|
156
157
|
ssr === 'fastify'
|
|
157
|
-
? new URL('src/vite/fastify/entry.ts', cliDir)
|
|
158
|
-
: new URL(`src/vite/${framework}/ssr/app.ts`, cliDir)
|
|
158
|
+
? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
|
|
159
|
+
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir))
|
|
159
160
|
|
|
160
161
|
;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
|
|
161
162
|
const app = fastify({
|
package/src/node/bin/test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { startVitest } from 'vitest/node'
|
|
2
2
|
import { baseConfig } from '../index.js'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
3
4
|
export async function test(opts: { appDir: URL }) {
|
|
4
5
|
const config = await baseConfig({
|
|
5
6
|
appDir: opts.appDir,
|
|
@@ -11,8 +12,8 @@ export async function test(opts: { appDir: URL }) {
|
|
|
11
12
|
'test',
|
|
12
13
|
[],
|
|
13
14
|
{
|
|
14
|
-
root: opts.appDir
|
|
15
|
-
dir: opts.appDir
|
|
15
|
+
root: fileURLToPath(opts.appDir),
|
|
16
|
+
dir: fileURLToPath(opts.appDir),
|
|
16
17
|
|
|
17
18
|
globals: true,
|
|
18
19
|
environment: 'happy-dom'
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from 'fastify'
|
|
6
6
|
import fastifyStatic from '@fastify/static'
|
|
7
7
|
import type { ViteDevServer } from 'vite'
|
|
8
|
-
|
|
8
|
+
import { fileURLToPath } from 'url'
|
|
9
9
|
export interface FastifySsrOptions {
|
|
10
10
|
baseUrl?: string
|
|
11
11
|
provide?: (
|
|
@@ -58,7 +58,7 @@ const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
58
58
|
} else {
|
|
59
59
|
options.appDir = options.appDir || new URL('../../..', import.meta.url)
|
|
60
60
|
fastify.register(fastifyStatic, {
|
|
61
|
-
root: new URL('./dist/csr', options.appDir)
|
|
61
|
+
root: fileURLToPath(new URL('./dist/csr', options.appDir)),
|
|
62
62
|
wildcard: false,
|
|
63
63
|
index: false,
|
|
64
64
|
prefix: options.baseUrl
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
} from 'fastify'
|
|
6
6
|
import fastifyStatic from '@fastify/static'
|
|
7
7
|
import { readFileSync } from 'fs'
|
|
8
|
+
import { fileURLToPath } from 'url'
|
|
8
9
|
import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
|
|
9
10
|
import {
|
|
10
11
|
addOrReplaceAppDiv,
|
|
@@ -48,11 +49,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
48
49
|
options.vitrifyDir =
|
|
49
50
|
options.vitrifyDir || (await import('vitrify')).vitrifyDir
|
|
50
51
|
const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir)
|
|
51
|
-
|
|
52
|
-
// throw new Error('Option vitrifyDir cannot be undefined')
|
|
53
|
-
// if (!options.vite) throw new Error('Option vite cannot be undefined')
|
|
54
|
-
// const { resolve } = await import('import-meta-resolve')
|
|
55
|
-
// const cliDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
52
|
+
|
|
56
53
|
options.appDir = options.appDir || new URL('../../..', import.meta.url)
|
|
57
54
|
|
|
58
55
|
const { createVitrifyDevServer } = await import('vitrify/dev')
|
|
@@ -63,38 +60,6 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
63
60
|
base: options.baseUrl,
|
|
64
61
|
host: options.host
|
|
65
62
|
})
|
|
66
|
-
// const { createServer, searchForWorkspaceRoot } = await import('vite')
|
|
67
|
-
// const { baseConfig } = await import('vitrify')
|
|
68
|
-
// const cliDir = options.vitrifyDir
|
|
69
|
-
// const config = await baseConfig({
|
|
70
|
-
// ssr: 'server',
|
|
71
|
-
// command: 'dev',
|
|
72
|
-
// mode: 'development',
|
|
73
|
-
// appDir: options.appDir,
|
|
74
|
-
// publicDir: options.publicDir || new URL('public', options.appDir)
|
|
75
|
-
// })
|
|
76
|
-
|
|
77
|
-
// config.server = {
|
|
78
|
-
// middlewareMode: true,
|
|
79
|
-
// fs: {
|
|
80
|
-
// allow: [
|
|
81
|
-
// searchForWorkspaceRoot(process.cwd()),
|
|
82
|
-
// searchForWorkspaceRoot(options.appDir.pathname),
|
|
83
|
-
// searchForWorkspaceRoot(cliDir.pathname)
|
|
84
|
-
// // appDir.pathname,
|
|
85
|
-
// ]
|
|
86
|
-
// },
|
|
87
|
-
// watch: {
|
|
88
|
-
// // During tests we edit the files too fast and sometimes chokidar
|
|
89
|
-
// // misses change events, so enforce polling for consistency
|
|
90
|
-
// usePolling: true,
|
|
91
|
-
// interval: 100
|
|
92
|
-
// }
|
|
93
|
-
// }
|
|
94
|
-
// const vite = await createServer({
|
|
95
|
-
// configFile: false,
|
|
96
|
-
// ...config
|
|
97
|
-
// })
|
|
98
63
|
|
|
99
64
|
if (!('use' in fastify)) {
|
|
100
65
|
const middie = (await import('@fastify/middie')).default
|
|
@@ -120,7 +85,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
120
85
|
|
|
121
86
|
template = await vite.transformIndexHtml(url!, template)
|
|
122
87
|
|
|
123
|
-
const entryUrl =
|
|
88
|
+
const entryUrl = fileURLToPath(
|
|
89
|
+
new URL('ssr/entry-server.ts', frameworkDir)
|
|
90
|
+
)
|
|
124
91
|
const render = (await vite!.ssrLoadModule(entryUrl)).render
|
|
125
92
|
let manifest
|
|
126
93
|
// TODO: https://github.com/vitejs/vite/issues/2282
|
|
@@ -186,7 +153,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
186
153
|
} else {
|
|
187
154
|
options.appDir = options.appDir || new URL('../../..', import.meta.url)
|
|
188
155
|
fastify.register(fastifyStatic, {
|
|
189
|
-
root: new URL('./dist/ssr/client', options.appDir)
|
|
156
|
+
root: fileURLToPath(new URL('./dist/ssr/client', options.appDir)),
|
|
190
157
|
wildcard: false,
|
|
191
158
|
index: false,
|
|
192
159
|
prefix: options.baseUrl
|
|
@@ -202,7 +169,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
202
169
|
}
|
|
203
170
|
|
|
204
171
|
const template = readFileSync(
|
|
205
|
-
new URL('./dist/ssr/client/index.html', options.appDir)
|
|
172
|
+
fileURLToPath(new URL('./dist/ssr/client/index.html', options.appDir))
|
|
206
173
|
).toString()
|
|
207
174
|
const manifest = JSON.parse(
|
|
208
175
|
readFileSync(
|
|
@@ -211,7 +178,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
211
178
|
)
|
|
212
179
|
const render = (
|
|
213
180
|
await import(
|
|
214
|
-
|
|
181
|
+
fileURLToPath(
|
|
182
|
+
new URL('./dist/ssr/server/entry-server.mjs', options.appDir)
|
|
183
|
+
)
|
|
215
184
|
)
|
|
216
185
|
).render
|
|
217
186
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from 'fs'
|
|
2
2
|
import type { OnRenderedHook } from 'src/node/vitrify-config.js'
|
|
3
3
|
import { routesToPaths } from '../../helpers/routes.js'
|
|
4
|
-
import { appendToHead,
|
|
4
|
+
import { appendToHead, addOrReplaceAppDiv } from '../../helpers/utils.js'
|
|
5
5
|
|
|
6
6
|
export const prerender = async ({
|
|
7
7
|
outDir,
|
|
@@ -31,6 +31,7 @@ export const prerender = async ({
|
|
|
31
31
|
inlineFonts: true,
|
|
32
32
|
preloadFonts: true
|
|
33
33
|
})
|
|
34
|
+
|
|
34
35
|
for (const url of paths) {
|
|
35
36
|
const filename =
|
|
36
37
|
(url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html'
|
|
@@ -41,10 +42,8 @@ export const prerender = async ({
|
|
|
41
42
|
}
|
|
42
43
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
43
44
|
|
|
44
|
-
let html =
|
|
45
|
-
|
|
45
|
+
let html = addOrReplaceAppDiv(appHtml, template)
|
|
46
46
|
html = appendToHead(preloadLinks, html)
|
|
47
|
-
// html = appendToBody(preloadLinks, html)
|
|
48
47
|
|
|
49
48
|
if (onRendered?.length) {
|
|
50
49
|
for (const ssrFunction of onRendered) {
|
package/src/node/index.ts
CHANGED
|
@@ -9,11 +9,17 @@ import { pathToFileURL } from 'url'
|
|
|
9
9
|
import { readFileSync } from 'fs'
|
|
10
10
|
import builtinModules from 'builtin-modules'
|
|
11
11
|
import { visualizer } from 'rollup-plugin-visualizer'
|
|
12
|
+
import { fileURLToPath } from 'url'
|
|
12
13
|
import type {
|
|
13
14
|
StaticImports,
|
|
14
15
|
BootFunction,
|
|
15
16
|
OnMountedHook,
|
|
16
17
|
VitrifyConfig,
|
|
18
|
+
VitrifyConfigAsync,
|
|
19
|
+
VitrifyCommands,
|
|
20
|
+
VitrifyModes,
|
|
21
|
+
VitrifyUIFrameworks,
|
|
22
|
+
VitrifySSRModes,
|
|
17
23
|
OnRenderedHook,
|
|
18
24
|
OnBootHook,
|
|
19
25
|
OnSetupFile
|
|
@@ -195,13 +201,13 @@ export const baseConfig = async ({
|
|
|
195
201
|
debug = false,
|
|
196
202
|
productName
|
|
197
203
|
}: {
|
|
198
|
-
ssr?:
|
|
204
|
+
ssr?: VitrifySSRModes
|
|
199
205
|
appDir?: URL
|
|
200
206
|
publicDir?: URL
|
|
201
207
|
base?: string
|
|
202
|
-
command?:
|
|
203
|
-
mode?:
|
|
204
|
-
framework?:
|
|
208
|
+
command?: VitrifyCommands
|
|
209
|
+
mode?: VitrifyModes
|
|
210
|
+
framework?: VitrifyUIFrameworks
|
|
205
211
|
pwa?: boolean
|
|
206
212
|
debug?: boolean
|
|
207
213
|
productName?: string
|
|
@@ -219,31 +225,21 @@ export const baseConfig = async ({
|
|
|
219
225
|
const fastifyDir = new URL('fastify/', cliViteDir)
|
|
220
226
|
|
|
221
227
|
if (!publicDir) publicDir = new URL('public/', appDir)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
*/
|
|
225
|
-
let vitrifyConfig:
|
|
226
|
-
| VitrifyConfig
|
|
227
|
-
| (({
|
|
228
|
-
mode,
|
|
229
|
-
command
|
|
230
|
-
}: {
|
|
231
|
-
mode: string
|
|
232
|
-
command: string
|
|
233
|
-
}) => Promise<VitrifyConfig> | VitrifyConfig)
|
|
228
|
+
|
|
229
|
+
let vitrifyConfig: VitrifyConfig | VitrifyConfigAsync
|
|
234
230
|
|
|
235
231
|
try {
|
|
236
|
-
if (fs.existsSync(new URL('vitrify.config.ts', appDir)
|
|
237
|
-
const configPath = new URL('vitrify.config.ts', appDir)
|
|
232
|
+
if (fs.existsSync(fileURLToPath(new URL('vitrify.config.ts', appDir)))) {
|
|
233
|
+
const configPath = fileURLToPath(new URL('vitrify.config.ts', appDir))
|
|
238
234
|
const bundledConfig = await bundleConfigFile(
|
|
239
|
-
new URL('vitrify.config.ts', appDir)
|
|
235
|
+
fileURLToPath(new URL('vitrify.config.ts', appDir))
|
|
240
236
|
)
|
|
241
237
|
fs.writeFileSync(configPath + '.js', bundledConfig.code)
|
|
242
238
|
vitrifyConfig = (await import(configPath + '.js')).default
|
|
243
239
|
fs.unlinkSync(configPath + '.js')
|
|
244
240
|
} else {
|
|
245
241
|
vitrifyConfig = (
|
|
246
|
-
await import(new URL('vitrify.config.js', appDir)
|
|
242
|
+
await import(fileURLToPath(new URL('vitrify.config.js', appDir)))
|
|
247
243
|
).default
|
|
248
244
|
}
|
|
249
245
|
if (typeof vitrifyConfig === 'function')
|
|
@@ -261,7 +257,7 @@ export const baseConfig = async ({
|
|
|
261
257
|
vitrifyConfig.vitrify?.urls?.packages || {}
|
|
262
258
|
await (async () => {
|
|
263
259
|
for (const val of localPackages) {
|
|
264
|
-
const pkg = resolvePackageData(val, appDir
|
|
260
|
+
const pkg = resolvePackageData(val, fileURLToPath(appDir))
|
|
265
261
|
if (pkg) packageUrls![val] = new URL(`file://${pkg.dir}/`)
|
|
266
262
|
}
|
|
267
263
|
})()
|
|
@@ -276,7 +272,7 @@ export const baseConfig = async ({
|
|
|
276
272
|
if (!productName) {
|
|
277
273
|
try {
|
|
278
274
|
;({ productName } = JSON.parse(
|
|
279
|
-
readFileSync(new URL('package.json', appDir)
|
|
275
|
+
readFileSync(fileURLToPath(new URL('package.json', appDir)), {
|
|
280
276
|
encoding: 'utf-8'
|
|
281
277
|
})
|
|
282
278
|
))
|
|
@@ -311,7 +307,6 @@ export const baseConfig = async ({
|
|
|
311
307
|
let globalCss: string[] = []
|
|
312
308
|
let staticImports: StaticImports
|
|
313
309
|
let sassVariables: Record<string, string>
|
|
314
|
-
let additionalData: string[]
|
|
315
310
|
let globalSass: string[]
|
|
316
311
|
let serverModules: string[] = internalServerModules
|
|
317
312
|
|
|
@@ -366,7 +361,6 @@ export const baseConfig = async ({
|
|
|
366
361
|
staticImports = config.vitrify?.staticImports || {}
|
|
367
362
|
sassVariables = config.vitrify?.sass?.variables || {}
|
|
368
363
|
globalSass = config.vitrify?.sass?.global || []
|
|
369
|
-
additionalData = config.vitrify?.sass?.additionalData || []
|
|
370
364
|
|
|
371
365
|
return
|
|
372
366
|
},
|
|
@@ -417,13 +411,15 @@ export const baseConfig = async ({
|
|
|
417
411
|
export const onSetup = []
|
|
418
412
|
${onSetupFiles
|
|
419
413
|
.map((url, index) => {
|
|
420
|
-
const varName = url
|
|
414
|
+
const varName = fileURLToPath(url)
|
|
421
415
|
.replaceAll('/', '')
|
|
422
416
|
.replaceAll('.', '')
|
|
423
417
|
.replaceAll('-', '')
|
|
424
418
|
.replaceAll('_', '')
|
|
425
419
|
.replaceAll('+', '')
|
|
426
|
-
return `import ${varName} from '${
|
|
420
|
+
return `import ${varName} from '${fileURLToPath(
|
|
421
|
+
url
|
|
422
|
+
)}'; onSetup.push(${varName})`
|
|
427
423
|
})
|
|
428
424
|
.join('\n')}`
|
|
429
425
|
} else if (id === 'virtual:static-imports') {
|
|
@@ -465,16 +461,6 @@ export const baseConfig = async ({
|
|
|
465
461
|
plugins.unshift({
|
|
466
462
|
name: 'html-transform',
|
|
467
463
|
enforce: 'pre',
|
|
468
|
-
// transform: (code, id) => {
|
|
469
|
-
// if (id.endsWith('App.vue')) {
|
|
470
|
-
// code =
|
|
471
|
-
// code +
|
|
472
|
-
// `<style lang="sass">
|
|
473
|
-
// // do not remove, required for additionalData import
|
|
474
|
-
// </style>`
|
|
475
|
-
// }
|
|
476
|
-
// return code
|
|
477
|
-
// },
|
|
478
464
|
transformIndexHtml: {
|
|
479
465
|
enforce: 'pre',
|
|
480
466
|
transform: (html) => {
|
|
@@ -483,13 +469,15 @@ export const baseConfig = async ({
|
|
|
483
469
|
case 'ssg':
|
|
484
470
|
case 'server':
|
|
485
471
|
case 'client':
|
|
486
|
-
entry =
|
|
472
|
+
entry = fileURLToPath(
|
|
473
|
+
new URL('ssr/entry-client.ts', frameworkDir)
|
|
474
|
+
)
|
|
487
475
|
break
|
|
488
476
|
case 'fastify':
|
|
489
|
-
entry = new URL('entry.ts', fastifyDir)
|
|
477
|
+
entry = fileURLToPath(new URL('entry.ts', fastifyDir))
|
|
490
478
|
break
|
|
491
479
|
default:
|
|
492
|
-
entry = new URL('csr/entry.ts', frameworkDir)
|
|
480
|
+
entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir))
|
|
493
481
|
}
|
|
494
482
|
const entryScript = `<script type="module" src="${entry}"></script>`
|
|
495
483
|
// html = html.replace('<!--entry-script-->', entryScript)
|
|
@@ -523,28 +511,26 @@ export const baseConfig = async ({
|
|
|
523
511
|
}
|
|
524
512
|
|
|
525
513
|
const alias: Alias[] = [
|
|
526
|
-
{ find: 'src', replacement: srcDir
|
|
527
|
-
{ find: 'app', replacement: appDir
|
|
528
|
-
{ find: 'cwd', replacement: cwd
|
|
529
|
-
{ find: 'boot', replacement: new URL('boot/', srcDir)
|
|
530
|
-
{ find: 'assets', replacement: new URL('assets/', srcDir)
|
|
514
|
+
{ find: 'src', replacement: fileURLToPath(srcDir) },
|
|
515
|
+
{ find: 'app', replacement: fileURLToPath(appDir) },
|
|
516
|
+
{ find: 'cwd', replacement: fileURLToPath(cwd) },
|
|
517
|
+
{ find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
|
|
518
|
+
{ find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
|
|
531
519
|
// ...Object.entries(packageUrls).map(([key, value]) => ({
|
|
532
520
|
// find: key,
|
|
533
521
|
// replacement: value.pathname
|
|
534
522
|
// }))
|
|
535
523
|
{
|
|
536
524
|
find: new RegExp('^vue$'),
|
|
537
|
-
replacement:
|
|
538
|
-
'./dist/vue.runtime.esm-bundler.js',
|
|
539
|
-
|
|
540
|
-
).pathname
|
|
525
|
+
replacement: fileURLToPath(
|
|
526
|
+
new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue'])
|
|
527
|
+
)
|
|
541
528
|
},
|
|
542
529
|
{
|
|
543
530
|
find: new RegExp('^vue-router$'),
|
|
544
|
-
replacement:
|
|
545
|
-
'./dist/vue-router.esm-bundler.js',
|
|
546
|
-
|
|
547
|
-
).pathname
|
|
531
|
+
replacement: fileURLToPath(
|
|
532
|
+
new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router'])
|
|
533
|
+
)
|
|
548
534
|
}
|
|
549
535
|
]
|
|
550
536
|
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
@@ -553,7 +539,7 @@ export const baseConfig = async ({
|
|
|
553
539
|
if (command === 'test')
|
|
554
540
|
alias.push({
|
|
555
541
|
find: 'vitest',
|
|
556
|
-
replacement: new URL(await resolve('vitest', cliDir))
|
|
542
|
+
replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
|
|
557
543
|
})
|
|
558
544
|
|
|
559
545
|
let rollupOptions: RollupOptions = {}
|
|
@@ -566,9 +552,9 @@ export const baseConfig = async ({
|
|
|
566
552
|
rollupOptions = {
|
|
567
553
|
...rollupOptions,
|
|
568
554
|
input: [
|
|
569
|
-
new URL('ssr/entry-server.ts', frameworkDir)
|
|
570
|
-
new URL('ssr/prerender.ts', frameworkDir)
|
|
571
|
-
new URL('ssr/server.ts', frameworkDir)
|
|
555
|
+
fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir)),
|
|
556
|
+
fileURLToPath(new URL('ssr/prerender.ts', frameworkDir)),
|
|
557
|
+
fileURLToPath(new URL('ssr/server.ts', frameworkDir))
|
|
572
558
|
],
|
|
573
559
|
external,
|
|
574
560
|
output: {
|
|
@@ -586,7 +572,7 @@ export const baseConfig = async ({
|
|
|
586
572
|
} else if (ssr === 'fastify') {
|
|
587
573
|
rollupOptions = {
|
|
588
574
|
...rollupOptions,
|
|
589
|
-
input: [new URL('server.ts', fastifyDir)
|
|
575
|
+
input: [fileURLToPath(new URL('server.ts', fastifyDir))],
|
|
590
576
|
external,
|
|
591
577
|
output: {
|
|
592
578
|
minifyInternalExports: false,
|
|
@@ -615,10 +601,10 @@ export const baseConfig = async ({
|
|
|
615
601
|
}
|
|
616
602
|
|
|
617
603
|
const config = {
|
|
618
|
-
root: appDir
|
|
619
|
-
publicDir: publicDir
|
|
604
|
+
root: fileURLToPath(appDir),
|
|
605
|
+
publicDir: fileURLToPath(publicDir),
|
|
620
606
|
base,
|
|
621
|
-
envDir: appDir
|
|
607
|
+
envDir: fileURLToPath(appDir),
|
|
622
608
|
vitrify: {
|
|
623
609
|
productName,
|
|
624
610
|
urls: {
|
|
@@ -659,4 +645,10 @@ export const baseConfig = async ({
|
|
|
659
645
|
|
|
660
646
|
export const vitrifyDir = new URL('..', import.meta.url)
|
|
661
647
|
export { prerender } from './frameworks/vue/prerender.js'
|
|
662
|
-
export type {
|
|
648
|
+
export type {
|
|
649
|
+
VitrifyConfig,
|
|
650
|
+
VitrifyConfigAsync,
|
|
651
|
+
VitrifyPlugin,
|
|
652
|
+
VitrifyContext,
|
|
653
|
+
BootFunction
|
|
654
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from 'vite'
|
|
2
2
|
import { resolvePackageData } from 'vite'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
3
4
|
import Components from 'unplugin-vue-components/vite'
|
|
4
5
|
import type {
|
|
5
6
|
OnBootHook,
|
|
@@ -115,7 +116,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
115
116
|
for (const val of localPackages) {
|
|
116
117
|
const pkg = resolvePackageData(
|
|
117
118
|
val,
|
|
118
|
-
config.vitrify!.urls!.app
|
|
119
|
+
fileURLToPath(config.vitrify!.urls!.app!)
|
|
119
120
|
)
|
|
120
121
|
if (pkg) urls!.packages![val] = new URL(`file://${pkg.dir}/`)
|
|
121
122
|
}
|
|
@@ -196,10 +197,9 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
196
197
|
alias: [
|
|
197
198
|
{
|
|
198
199
|
find: 'quasar/src/',
|
|
199
|
-
replacement:
|
|
200
|
-
'./src/',
|
|
201
|
-
|
|
202
|
-
).pathname
|
|
200
|
+
replacement: fileURLToPath(
|
|
201
|
+
new URL('./src/', config.vitrify!.urls!.packages!.quasar)
|
|
202
|
+
)
|
|
203
203
|
}
|
|
204
204
|
]
|
|
205
205
|
},
|
|
@@ -73,7 +73,6 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
73
73
|
*/
|
|
74
74
|
sass?: {
|
|
75
75
|
variables?: Record<string, string>
|
|
76
|
-
additionalData?: string[]
|
|
77
76
|
global?: string[]
|
|
78
77
|
}
|
|
79
78
|
/**
|
|
@@ -111,8 +110,17 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
111
110
|
quasar?: QuasarConf
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
export type
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
export type VitrifyCommands = 'build' | 'dev' | 'test'
|
|
114
|
+
export type VitrifyModes = 'production' | 'development'
|
|
115
|
+
export type VitrifyUIFrameworks = 'vue'
|
|
116
|
+
export type VitrifySSRModes = 'client' | 'server' | 'ssg' | 'fastify'
|
|
117
|
+
|
|
118
|
+
export type VitrifyConfigAsync = ({
|
|
119
|
+
mode,
|
|
120
|
+
command
|
|
121
|
+
}: {
|
|
122
|
+
mode: VitrifyModes
|
|
123
|
+
command: VitrifyCommands
|
|
124
|
+
}) => Promise<VitrifyConfig>
|
|
117
125
|
|
|
118
126
|
export const defineConfig = (config: VitrifyConfig) => config
|