vitrify 0.8.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -9
- package/dist/bin/cli.js +4 -1
- package/dist/bin/dev.js +17 -2
- package/dist/frameworks/vue/fastify-ssr-plugin.js +13 -3
- package/dist/helpers/logger.js +1 -0
- package/dist/index.js +1 -0
- package/dist/plugins/quasar.js +11 -3
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +1 -0
- package/dist/types/helpers/logger.d.ts +1 -0
- package/dist/types/plugins/quasar.d.ts +5 -5
- package/package.json +8 -2
- package/src/node/bin/cli.ts +5 -8
- package/src/node/bin/dev.ts +22 -2
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +20 -3
- package/src/node/helpers/logger.ts +2 -0
- package/src/node/index.ts +1 -0
- package/src/node/plugins/quasar.ts +18 -8
- package/src/vite/vue/main.ts +6 -1
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# Vitrify
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Vite as your Full Stack development tool
|
|
4
4
|
|
|
5
5
|
- Use a simple configuration file to configure and integrate required Vite plugins into your project.
|
|
6
|
-
- Client-Side Rendering (CSR), Server-Side Rendering (SSR) and Fastify server build and development modes.
|
|
6
|
+
- Client-Side Rendering (CSR), Server-Side Rendering (SSR), Static Site Generation (SSG) and Fastify server build and development modes.
|
|
7
|
+
- Run both your frontend- and backend code through Vite at development and build time.
|
|
7
8
|
|
|
8
9
|
## Features
|
|
9
10
|
|
|
@@ -73,14 +74,24 @@ Options:
|
|
|
73
74
|
node/bin/cli.ts-->node/bin/dev.ts;
|
|
74
75
|
node/bin/cli.ts-->node/bin/test.ts;
|
|
75
76
|
node/bin/cli.ts-->node/bin/run.ts;
|
|
76
|
-
node/bin/build.ts-->node/index.ts
|
|
77
|
-
node/bin/dev.ts-->node/index.ts
|
|
78
|
-
node/index.ts-->vitrify.config.js{Load vitrify.config.js};
|
|
77
|
+
node/bin/build.ts-->node/index.ts
|
|
78
|
+
node/bin/dev.ts-->node/index.ts
|
|
79
|
+
node/index.ts{Load baseConfig}-->vitrify.config.js{Load vitrify.config.js};
|
|
80
|
+
subgraph baseconfig
|
|
79
81
|
vitrify.config.js-->node/plugins{Load plugins};
|
|
80
|
-
node/plugins-->
|
|
81
|
-
|
|
82
|
-
merge-->
|
|
83
|
-
merge-->
|
|
82
|
+
node/plugins-->merge{Merge vitrify.config.js with Vitrify configuration};
|
|
83
|
+
end
|
|
84
|
+
merge-- mode: fastify -->frameworkFastify{Load framework entrypoints from fastify/...};
|
|
85
|
+
merge-- mode: csr/ssr/ssg -->framework{Load framework entrypoints from vite/...};
|
|
86
|
+
frameworkFastify-->fastifyBuild{Build the application};
|
|
87
|
+
frameworkFastify-->fastifyDev{Start Fastify dev server};
|
|
88
|
+
fastifySetup{onSetup / onRendered}-->fastifyDev
|
|
89
|
+
fastifySetup{onSetup / onRendered}-->fastifyBuild
|
|
90
|
+
framework-->build{Build the application};
|
|
91
|
+
build-- mode: ssg -->prerender{Run prerender.js}
|
|
92
|
+
framework-->dev{Start Vite dev server};
|
|
93
|
+
frameworkSetup{onBoot / onMounted}-->dev
|
|
94
|
+
frameworkSetup{onBoot / onMounted}-->build
|
|
84
95
|
node/bin/test.ts-->test{Run a pre-configured Vitest instance};
|
|
85
96
|
node/bin/run.ts-->run{Inject context into script and run script};
|
|
86
97
|
```
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import { getAppDir, parsePath } from '../app-urls.js';
|
|
4
|
-
import { printHttpServerUrls } from '../helpers/logger.js';
|
|
4
|
+
import { printHttpServerUrls, exitLogs } from '../helpers/logger.js';
|
|
5
5
|
const cli = cac('vitrify');
|
|
6
6
|
cli
|
|
7
7
|
.command('build')
|
|
@@ -135,6 +135,9 @@ cli
|
|
|
135
135
|
}
|
|
136
136
|
console.log('Dev server running at:');
|
|
137
137
|
printHttpServerUrls(server, config);
|
|
138
|
+
for (const line of exitLogs) {
|
|
139
|
+
config.logger.warn(line);
|
|
140
|
+
}
|
|
138
141
|
});
|
|
139
142
|
cli.command('test').action(async (options) => {
|
|
140
143
|
const { test } = await import('./test.js');
|
package/dist/bin/dev.js
CHANGED
|
@@ -2,6 +2,14 @@ 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
|
+
import isPortReachable from 'is-port-reachable';
|
|
6
|
+
import { exitLogs } from '../helpers/logger.js';
|
|
7
|
+
const getFirstOpenPort = async (portNumber) => {
|
|
8
|
+
if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
|
|
9
|
+
return portNumber;
|
|
10
|
+
}
|
|
11
|
+
return getFirstOpenPort(portNumber + 1);
|
|
12
|
+
};
|
|
5
13
|
export async function createVitrifyDevServer({ port = 3000, logLevel = 'info',
|
|
6
14
|
// mode = 'csr',
|
|
7
15
|
ssr, framework = 'vue', host, appDir, publicDir, base }) {
|
|
@@ -25,11 +33,17 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
|
|
|
25
33
|
base
|
|
26
34
|
});
|
|
27
35
|
config.logLevel = logLevel;
|
|
36
|
+
config.define = {
|
|
37
|
+
...config.define,
|
|
38
|
+
__HOST__: `'${host}'`
|
|
39
|
+
};
|
|
40
|
+
const wsPort = await getFirstOpenPort(24678);
|
|
41
|
+
exitLogs.push(`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`);
|
|
28
42
|
config.server = {
|
|
29
43
|
https: config.server?.https,
|
|
30
44
|
hmr: {
|
|
31
45
|
protocol: config.server?.https ? 'wss' : 'ws',
|
|
32
|
-
port:
|
|
46
|
+
port: wsPort
|
|
33
47
|
},
|
|
34
48
|
port,
|
|
35
49
|
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
|
|
@@ -100,7 +114,8 @@ ssr, framework = 'vue', host, appDir, publicDir }) {
|
|
|
100
114
|
await app.register(fastifySsrPlugin, {
|
|
101
115
|
appDir,
|
|
102
116
|
mode: 'development',
|
|
103
|
-
onRendered
|
|
117
|
+
onRendered,
|
|
118
|
+
host
|
|
104
119
|
});
|
|
105
120
|
}
|
|
106
121
|
await app.listen({
|
|
@@ -23,7 +23,8 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
23
23
|
appDir: options.appDir,
|
|
24
24
|
ssr: 'ssr',
|
|
25
25
|
framework: 'vue',
|
|
26
|
-
base: options.baseUrl
|
|
26
|
+
base: options.baseUrl,
|
|
27
|
+
host: options.host
|
|
27
28
|
});
|
|
28
29
|
// const { createServer, searchForWorkspaceRoot } = await import('vite')
|
|
29
30
|
// const { baseConfig } = await import('vitrify')
|
|
@@ -91,11 +92,17 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
91
92
|
mods: matchedModules
|
|
92
93
|
});
|
|
93
94
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
|
|
95
|
+
if (!ssrContext.initialState)
|
|
96
|
+
ssrContext.initialState = {};
|
|
97
|
+
ssrContext.initialState.provide = provide;
|
|
94
98
|
let html = template
|
|
95
99
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
96
100
|
.replace(`<!--app-html-->`, appHtml)
|
|
97
101
|
.replace('<!--product-name-->', options.productName || 'Product name')
|
|
98
|
-
.replace('<!--dev-ssr-css-->', css)
|
|
102
|
+
.replace('<!--dev-ssr-css-->', css)
|
|
103
|
+
.replace('<!--initial-state-->', `<script>
|
|
104
|
+
__INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
|
|
105
|
+
</script>`);
|
|
99
106
|
if (options.onRendered?.length) {
|
|
100
107
|
for (const ssrFunction of options.onRendered) {
|
|
101
108
|
html = ssrFunction(html, ssrContext);
|
|
@@ -139,7 +146,10 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
139
146
|
ssrContext.initialState.provide = provide;
|
|
140
147
|
let html = template
|
|
141
148
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
142
|
-
.replace(`<!--app-html-->`, appHtml)
|
|
149
|
+
.replace(`<!--app-html-->`, appHtml)
|
|
150
|
+
.replace('<!--initial-state-->', `<script>
|
|
151
|
+
__INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
|
|
152
|
+
</script>`);
|
|
143
153
|
if (options.onRendered?.length) {
|
|
144
154
|
for (const ssrFunction of options.onRendered) {
|
|
145
155
|
html = ssrFunction(html, ssrContext);
|
package/dist/helpers/logger.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import { resolveHostname } from '../helpers/utils.js';
|
|
5
|
+
export const exitLogs = [];
|
|
5
6
|
export function printHttpServerUrls(server, config) {
|
|
6
7
|
const address = server.address();
|
|
7
8
|
const isAddressInfo = (x) => x?.address;
|
package/dist/index.js
CHANGED
package/dist/plugins/quasar.js
CHANGED
|
@@ -38,7 +38,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
38
38
|
name: 'vite-plugin-quasar-transform',
|
|
39
39
|
enforce: 'pre',
|
|
40
40
|
transform: (code, id, options) => {
|
|
41
|
-
const { ssr } = options || {};
|
|
42
41
|
code = code
|
|
43
42
|
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
44
43
|
.replaceAll('__QUASAR_SSR_SERVER__', ssr ? '(import.meta.env.SSR === true)' : 'false')
|
|
@@ -52,7 +51,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
52
51
|
enforce: 'pre',
|
|
53
52
|
config: async (config, env) => {
|
|
54
53
|
const { vitrify: { urls } = {}, quasar } = config;
|
|
55
|
-
const globalCss = quasar?.extras
|
|
54
|
+
const globalCss = quasar?.extras?.map((extra) => `@quasar/extras/${extra}/${extra}.css`);
|
|
56
55
|
const localPackages = ['@quasar/extras', 'quasar'];
|
|
57
56
|
// const localPackages: string[] = []
|
|
58
57
|
await (async () => {
|
|
@@ -77,10 +76,13 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
77
76
|
const directives = await import('virtual:quasar-directives');
|
|
78
77
|
// @ts-ignore
|
|
79
78
|
const { default: lang } = await import('virtual:quasar-lang');
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
const { default: iconSet } = await import('virtual:quasar-iconSet');
|
|
80
81
|
app.use(staticImports?.Quasar, {
|
|
81
82
|
plugins: quasarPlugins,
|
|
82
83
|
directives,
|
|
83
|
-
lang
|
|
84
|
+
lang,
|
|
85
|
+
iconSet
|
|
84
86
|
}, ssrContext);
|
|
85
87
|
}
|
|
86
88
|
];
|
|
@@ -163,6 +165,8 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
163
165
|
return 'virtual:quasar-directives';
|
|
164
166
|
case 'virtual:quasar-lang':
|
|
165
167
|
return 'virtual:quasar-lang';
|
|
168
|
+
case 'virtual:quasar-iconSet':
|
|
169
|
+
return 'virtual:quasar-iconSet';
|
|
166
170
|
case 'virtual:quasar':
|
|
167
171
|
return { id: 'virtual:quasar', moduleSideEffects: false };
|
|
168
172
|
default:
|
|
@@ -179,6 +183,10 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
179
183
|
else if (id === 'virtual:quasar-lang') {
|
|
180
184
|
return `import lang from 'quasar/lang/${quasarConf?.framework?.lang || 'en-US'}';
|
|
181
185
|
export default lang`;
|
|
186
|
+
}
|
|
187
|
+
else if (id === 'virtual:quasar-iconSet') {
|
|
188
|
+
return `import iconSet from 'quasar/icon-set/${quasarConf?.framework.iconSet || 'material-icons'}';
|
|
189
|
+
export default iconSet`;
|
|
182
190
|
}
|
|
183
191
|
else if (id === 'virtual:quasar') {
|
|
184
192
|
return `export * from 'quasar/src/plugins.js';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { VitrifyPlugin } from './index.js';
|
|
2
2
|
export interface QuasarConf {
|
|
3
|
-
ctx
|
|
4
|
-
css
|
|
5
|
-
boot
|
|
3
|
+
ctx?: Record<string, any>;
|
|
4
|
+
css?: string[];
|
|
5
|
+
boot?: string[];
|
|
6
6
|
framework: {
|
|
7
7
|
components?: string[];
|
|
8
8
|
directives?: string[];
|
|
9
9
|
plugins?: string[];
|
|
10
10
|
lang?: string;
|
|
11
|
+
iconSet?: string;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
extras: string[];
|
|
13
|
+
extras?: string[];
|
|
14
14
|
}
|
|
15
15
|
export declare const injectSsrContext: (html: string, ssrContext: Record<string, any>) => string;
|
|
16
16
|
export declare const QuasarPlugin: VitrifyPlugin;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Vite as your Full Stack development tool",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
9
|
"vitrify": "./dist/bin/cli.js"
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"fastify": "^4.3.0",
|
|
71
71
|
"glob": "^8.0.3",
|
|
72
72
|
"happy-dom": "^6.0.4",
|
|
73
|
+
"is-port-reachable": "^4.0.0",
|
|
73
74
|
"magic-string": "^0.26.2",
|
|
74
75
|
"merge-deep": "^3.0.3",
|
|
75
76
|
"readline": "^1.3.0",
|
|
@@ -109,5 +110,10 @@
|
|
|
109
110
|
"src",
|
|
110
111
|
"!dist/**/*.test.js",
|
|
111
112
|
"!dist/**/test.js"
|
|
113
|
+
],
|
|
114
|
+
"keywords": [
|
|
115
|
+
"vite",
|
|
116
|
+
"full stack",
|
|
117
|
+
"fastify"
|
|
112
118
|
]
|
|
113
119
|
}
|
package/src/node/bin/cli.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import cac from 'cac'
|
|
3
3
|
import { getAppDir, parsePath } from '../app-urls.js'
|
|
4
|
-
import { printHttpServerUrls } from '../helpers/logger.js'
|
|
5
|
-
import type {
|
|
6
|
-
ConfigEnv,
|
|
7
|
-
ResolvedConfig,
|
|
8
|
-
UserConfig,
|
|
9
|
-
UserConfigExport,
|
|
10
|
-
ViteDevServer
|
|
11
|
-
} from 'vite'
|
|
4
|
+
import { printHttpServerUrls, exitLogs } from '../helpers/logger.js'
|
|
5
|
+
import type { ResolvedConfig } from 'vite'
|
|
12
6
|
import type { Server } from 'net'
|
|
13
7
|
|
|
14
8
|
const cli = cac('vitrify')
|
|
@@ -157,6 +151,9 @@ cli
|
|
|
157
151
|
}
|
|
158
152
|
console.log('Dev server running at:')
|
|
159
153
|
printHttpServerUrls(server, config)
|
|
154
|
+
for (const line of exitLogs) {
|
|
155
|
+
config.logger.warn(line)
|
|
156
|
+
}
|
|
160
157
|
})
|
|
161
158
|
|
|
162
159
|
cli.command('test').action(async (options) => {
|
package/src/node/bin/dev.ts
CHANGED
|
@@ -6,6 +6,15 @@ import fastify from 'fastify'
|
|
|
6
6
|
import type { FastifyServerOptions } from 'fastify'
|
|
7
7
|
import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
|
|
8
8
|
import type { OnRenderedHook, VitrifyConfig } from '../vitrify-config.js'
|
|
9
|
+
import isPortReachable from 'is-port-reachable'
|
|
10
|
+
import { exitLogs } from '../helpers/logger.js'
|
|
11
|
+
|
|
12
|
+
const getFirstOpenPort = async (portNumber: number): Promise<number> => {
|
|
13
|
+
if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
|
|
14
|
+
return portNumber
|
|
15
|
+
}
|
|
16
|
+
return getFirstOpenPort(portNumber + 1)
|
|
17
|
+
}
|
|
9
18
|
|
|
10
19
|
export async function createVitrifyDevServer({
|
|
11
20
|
port = 3000,
|
|
@@ -51,11 +60,21 @@ export async function createVitrifyDevServer({
|
|
|
51
60
|
|
|
52
61
|
config.logLevel = logLevel
|
|
53
62
|
|
|
63
|
+
config.define = {
|
|
64
|
+
...config.define,
|
|
65
|
+
__HOST__: `'${host}'`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const wsPort = await getFirstOpenPort(24678)
|
|
69
|
+
exitLogs.push(
|
|
70
|
+
`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
|
|
71
|
+
)
|
|
72
|
+
|
|
54
73
|
config.server = {
|
|
55
74
|
https: config.server?.https,
|
|
56
75
|
hmr: {
|
|
57
76
|
protocol: config.server?.https ? 'wss' : 'ws',
|
|
58
|
-
port:
|
|
77
|
+
port: wsPort
|
|
59
78
|
},
|
|
60
79
|
port,
|
|
61
80
|
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
|
|
@@ -153,7 +172,8 @@ export async function createServer({
|
|
|
153
172
|
await app.register(fastifySsrPlugin, {
|
|
154
173
|
appDir,
|
|
155
174
|
mode: 'development',
|
|
156
|
-
onRendered
|
|
175
|
+
onRendered,
|
|
176
|
+
host
|
|
157
177
|
})
|
|
158
178
|
}
|
|
159
179
|
await app.listen({
|
|
@@ -8,7 +8,6 @@ import { readFileSync } from 'fs'
|
|
|
8
8
|
import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
|
|
9
9
|
import type { ViteDevServer } from 'vite'
|
|
10
10
|
import type { OnRenderedHook } from 'src/node/vitrify-config.js'
|
|
11
|
-
|
|
12
11
|
export interface FastifySsrOptions {
|
|
13
12
|
baseUrl?: string
|
|
14
13
|
provide?: (
|
|
@@ -23,6 +22,7 @@ export interface FastifySsrOptions {
|
|
|
23
22
|
publicDir?: URL
|
|
24
23
|
productName?: string
|
|
25
24
|
mode?: string
|
|
25
|
+
host?: string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
@@ -55,7 +55,8 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
55
55
|
appDir: options.appDir,
|
|
56
56
|
ssr: 'ssr',
|
|
57
57
|
framework: 'vue',
|
|
58
|
-
base: options.baseUrl
|
|
58
|
+
base: options.baseUrl,
|
|
59
|
+
host: options.host
|
|
59
60
|
})
|
|
60
61
|
// const { createServer, searchForWorkspaceRoot } = await import('vite')
|
|
61
62
|
// const { baseConfig } = await import('vitrify')
|
|
@@ -101,7 +102,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
101
102
|
const url = req.raw.url?.replace(options.baseUrl!, '/')
|
|
102
103
|
const provide = options.provide ? await options.provide(req, res) : {}
|
|
103
104
|
|
|
104
|
-
const ssrContext = {
|
|
105
|
+
const ssrContext: Record<string, any> = {
|
|
105
106
|
req,
|
|
106
107
|
res,
|
|
107
108
|
provide
|
|
@@ -133,11 +134,21 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
133
134
|
})
|
|
134
135
|
|
|
135
136
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
137
|
+
|
|
138
|
+
if (!ssrContext.initialState) ssrContext.initialState = {}
|
|
139
|
+
ssrContext.initialState.provide = provide
|
|
140
|
+
|
|
136
141
|
let html = template
|
|
137
142
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
138
143
|
.replace(`<!--app-html-->`, appHtml)
|
|
139
144
|
.replace('<!--product-name-->', options.productName || 'Product name')
|
|
140
145
|
.replace('<!--dev-ssr-css-->', css)
|
|
146
|
+
.replace(
|
|
147
|
+
'<!--initial-state-->',
|
|
148
|
+
`<script>
|
|
149
|
+
__INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
|
|
150
|
+
</script>`
|
|
151
|
+
)
|
|
141
152
|
|
|
142
153
|
if (options.onRendered?.length) {
|
|
143
154
|
for (const ssrFunction of options.onRendered) {
|
|
@@ -196,6 +207,12 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
196
207
|
let html = template
|
|
197
208
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
198
209
|
.replace(`<!--app-html-->`, appHtml)
|
|
210
|
+
.replace(
|
|
211
|
+
'<!--initial-state-->',
|
|
212
|
+
`<script>
|
|
213
|
+
__INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
|
|
214
|
+
</script>`
|
|
215
|
+
)
|
|
199
216
|
|
|
200
217
|
if (options.onRendered?.length) {
|
|
201
218
|
for (const ssrFunction of options.onRendered) {
|
package/src/node/index.ts
CHANGED
|
@@ -9,17 +9,18 @@ import type {
|
|
|
9
9
|
import { QuasarResolver } from 'unplugin-vue-components/resolvers'
|
|
10
10
|
import type { VitrifyPlugin } from './index.js'
|
|
11
11
|
export interface QuasarConf {
|
|
12
|
-
ctx
|
|
13
|
-
css
|
|
14
|
-
boot
|
|
12
|
+
ctx?: Record<string, any>
|
|
13
|
+
css?: string[]
|
|
14
|
+
boot?: string[]
|
|
15
15
|
framework: {
|
|
16
16
|
components?: string[]
|
|
17
17
|
directives?: string[]
|
|
18
18
|
plugins?: string[]
|
|
19
19
|
lang?: string
|
|
20
|
+
iconSet?: string
|
|
20
21
|
}
|
|
21
|
-
animations: string[]
|
|
22
|
-
extras
|
|
22
|
+
// animations: string[]
|
|
23
|
+
extras?: string[]
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export const injectSsrContext = (
|
|
@@ -84,7 +85,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
84
85
|
name: 'vite-plugin-quasar-transform',
|
|
85
86
|
enforce: 'pre',
|
|
86
87
|
transform: (code, id, options) => {
|
|
87
|
-
const { ssr } = options || {}
|
|
88
88
|
code = code
|
|
89
89
|
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
90
90
|
.replaceAll(
|
|
@@ -109,7 +109,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
109
109
|
config: async (config: VitrifyConfig, env): Promise<VitrifyConfig> => {
|
|
110
110
|
const { vitrify: { urls } = {}, quasar } = config
|
|
111
111
|
|
|
112
|
-
const globalCss = quasar?.extras
|
|
112
|
+
const globalCss = quasar?.extras?.map(
|
|
113
113
|
(extra) => `@quasar/extras/${extra}/${extra}.css`
|
|
114
114
|
)
|
|
115
115
|
|
|
@@ -143,13 +143,16 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
143
143
|
const directives = await import('virtual:quasar-directives')
|
|
144
144
|
// @ts-ignore
|
|
145
145
|
const { default: lang } = await import('virtual:quasar-lang')
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
const { default: iconSet } = await import('virtual:quasar-iconSet')
|
|
146
148
|
|
|
147
149
|
app.use(
|
|
148
150
|
staticImports?.Quasar,
|
|
149
151
|
{
|
|
150
152
|
plugins: quasarPlugins,
|
|
151
153
|
directives,
|
|
152
|
-
lang
|
|
154
|
+
lang,
|
|
155
|
+
iconSet
|
|
153
156
|
},
|
|
154
157
|
ssrContext
|
|
155
158
|
)
|
|
@@ -239,6 +242,8 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
239
242
|
return 'virtual:quasar-directives'
|
|
240
243
|
case 'virtual:quasar-lang':
|
|
241
244
|
return 'virtual:quasar-lang'
|
|
245
|
+
case 'virtual:quasar-iconSet':
|
|
246
|
+
return 'virtual:quasar-iconSet'
|
|
242
247
|
case 'virtual:quasar':
|
|
243
248
|
return { id: 'virtual:quasar', moduleSideEffects: false }
|
|
244
249
|
default:
|
|
@@ -255,6 +260,11 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
255
260
|
quasarConf?.framework?.lang || 'en-US'
|
|
256
261
|
}';
|
|
257
262
|
export default lang`
|
|
263
|
+
} else if (id === 'virtual:quasar-iconSet') {
|
|
264
|
+
return `import iconSet from 'quasar/icon-set/${
|
|
265
|
+
quasarConf?.framework.iconSet || 'material-icons'
|
|
266
|
+
}';
|
|
267
|
+
export default iconSet`
|
|
258
268
|
} else if (id === 'virtual:quasar') {
|
|
259
269
|
return `export * from 'quasar/src/plugins.js';
|
|
260
270
|
export * from 'quasar/src/components.js';
|
package/src/vite/vue/main.ts
CHANGED
|
@@ -55,6 +55,7 @@ export async function createApp(
|
|
|
55
55
|
next()
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
+
let initialState: Record<string, any>
|
|
58
59
|
let provide: Record<string, unknown> = {}
|
|
59
60
|
if (import.meta.env.SSR) {
|
|
60
61
|
if (ssrContext?.provide) {
|
|
@@ -62,7 +63,11 @@ export async function createApp(
|
|
|
62
63
|
}
|
|
63
64
|
} else {
|
|
64
65
|
// @ts-ignore
|
|
65
|
-
|
|
66
|
+
if (window.__INITIAL_STATE__) {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
initialState = JSON.parse(window.__INITIAL_STATE__)
|
|
69
|
+
provide = initialState.provide
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
for (let key in provide) {
|
|
68
73
|
app.provide(key, provide[key])
|