@poveste/plugin-nuxt 0.1.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/LICENSE +22 -0
- package/README.md +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +171 -0
- package/dist/runtime/app-setup.d.ts +2 -0
- package/dist/runtime/app-setup.js +46 -0
- package/package.json +48 -0
- package/runtime/app-component.mjs +3 -0
- package/runtime/components.mjs +14 -0
- package/runtime/composables.mjs +1 -0
- package/src/global.d.ts +5 -0
- package/src/index.ts +191 -0
- package/src/runtime/app-setup.ts +72 -0
- package/tsconfig.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Guillaume Chau (original "histoire" project)
|
|
4
|
+
Copyright (c) 2026 Sorin Gitlan (poveste fork)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Poveste + Nuxt 3
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
pnpm add -D @poveste/plugin-nuxt
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Add the plugin in histoire config:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { HstNuxt } from '@poveste/plugin-nuxt'
|
|
11
|
+
import { defineConfig } from 'poveste'
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [
|
|
15
|
+
HstNuxt(),
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import replace from '@rollup/plugin-replace';
|
|
4
|
+
const ignorePlugins = [
|
|
5
|
+
'nuxt:vite-node-server',
|
|
6
|
+
'nuxt:dev-style-ssr',
|
|
7
|
+
'nuxt:vite-relative-asset',
|
|
8
|
+
'nuxt:cache-dir',
|
|
9
|
+
'nuxt:dynamic-base-path',
|
|
10
|
+
'nuxt:import-protection',
|
|
11
|
+
];
|
|
12
|
+
export function HstNuxt() {
|
|
13
|
+
let nuxt;
|
|
14
|
+
return {
|
|
15
|
+
name: '@poveste/plugin-nuxt',
|
|
16
|
+
async defaultConfig() {
|
|
17
|
+
const nuxtViteConfig = await useNuxtViteConfig();
|
|
18
|
+
const { viteConfig } = nuxtViteConfig;
|
|
19
|
+
nuxt = nuxtViteConfig.nuxt; // We save it to close it later
|
|
20
|
+
const plugins = viteConfig.plugins.filter((p) => !ignorePlugins.includes(p?.name));
|
|
21
|
+
return {
|
|
22
|
+
vite: {
|
|
23
|
+
server: {
|
|
24
|
+
watch: viteConfig.server.watch,
|
|
25
|
+
fs: {
|
|
26
|
+
allow: viteConfig.server.fs.allow,
|
|
27
|
+
},
|
|
28
|
+
middlewareMode: false,
|
|
29
|
+
},
|
|
30
|
+
define: {
|
|
31
|
+
...viteConfig.define,
|
|
32
|
+
'process.server': false,
|
|
33
|
+
'process.client': true,
|
|
34
|
+
'process.browser': true,
|
|
35
|
+
'process.nitro': false,
|
|
36
|
+
'process.prerender': false,
|
|
37
|
+
},
|
|
38
|
+
resolve: {
|
|
39
|
+
alias: viteConfig.resolve.alias,
|
|
40
|
+
extensions: viteConfig.resolve.extensions,
|
|
41
|
+
dedupe: viteConfig.resolve.dedupe,
|
|
42
|
+
},
|
|
43
|
+
plugins: [
|
|
44
|
+
...plugins,
|
|
45
|
+
replace({
|
|
46
|
+
values: {
|
|
47
|
+
'import.meta.server': 'false',
|
|
48
|
+
'import.meta.client': 'true',
|
|
49
|
+
},
|
|
50
|
+
preventAssignment: true,
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
css: viteConfig.css,
|
|
54
|
+
publicDir: viteConfig.publicDir,
|
|
55
|
+
optimizeDeps: {
|
|
56
|
+
...viteConfig.optimizeDeps,
|
|
57
|
+
exclude: [
|
|
58
|
+
...viteConfig.optimizeDeps.exclude,
|
|
59
|
+
'@poveste/plugin-nuxt',
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
// @ts-expect-error Vue-specific config
|
|
63
|
+
vue: viteConfig.vue,
|
|
64
|
+
logLevel: 'info',
|
|
65
|
+
},
|
|
66
|
+
setupCode: [
|
|
67
|
+
`${nuxt.options.css.map(file => `import '${file}'`).join('\n')}`,
|
|
68
|
+
`import { setupNuxtApp } from '@poveste/plugin-nuxt/dist/runtime/app-setup.js'
|
|
69
|
+
export async function setupVue3 () {
|
|
70
|
+
await setupNuxtApp(${JSON.stringify(nuxt.options.runtimeConfig.public)})
|
|
71
|
+
}`,
|
|
72
|
+
],
|
|
73
|
+
viteNodeInlineDeps: [
|
|
74
|
+
/\/(nuxt|nuxt3)\//,
|
|
75
|
+
/^#/,
|
|
76
|
+
/\.nuxt/,
|
|
77
|
+
...nuxt.options.build.transpile.filter(r => typeof r === 'string' || r instanceof RegExp),
|
|
78
|
+
],
|
|
79
|
+
build: {
|
|
80
|
+
excludeFromVendorsChunk: [
|
|
81
|
+
/nuxt\/dist\/app/,
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
onDev(api, onCleanup) {
|
|
87
|
+
onCleanup(async () => {
|
|
88
|
+
nuxt?.close();
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
onBuild(api) {
|
|
92
|
+
api.onBuildEnd(() => {
|
|
93
|
+
nuxt?.close();
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
onPreview() {
|
|
97
|
+
nuxt?.close();
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function useNuxtViteConfig() {
|
|
102
|
+
const { loadNuxt, buildNuxt } = await import('@nuxt/kit');
|
|
103
|
+
const nuxt = await loadNuxt({
|
|
104
|
+
// cwd: process.cwd(),
|
|
105
|
+
ready: false,
|
|
106
|
+
dev: true,
|
|
107
|
+
overrides: {
|
|
108
|
+
devtools: { enabled: false },
|
|
109
|
+
ssr: false,
|
|
110
|
+
experimental: {
|
|
111
|
+
appManifest: false,
|
|
112
|
+
},
|
|
113
|
+
app: {
|
|
114
|
+
rootId: 'nuxt-test',
|
|
115
|
+
},
|
|
116
|
+
pages: false,
|
|
117
|
+
typescript: {
|
|
118
|
+
typeCheck: false,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
if (nuxt.options.builder !== '@nuxt/vite-builder') {
|
|
123
|
+
throw new Error(`Poveste only supports Vite bundler, but Nuxt builder is currently set to '${nuxt.options.builder}'.`);
|
|
124
|
+
}
|
|
125
|
+
const runtimeDir = fileURLToPath(new URL('../runtime', import.meta.url));
|
|
126
|
+
nuxt.options.build.templates.push({ src: join(runtimeDir, 'composables.mjs'), filename: 'poveste/composables.mjs' }, { src: join(runtimeDir, 'components.mjs'), filename: 'poveste/components.mjs' });
|
|
127
|
+
nuxt.hook('app:templates', (app) => {
|
|
128
|
+
app.templates = app.templates.filter(template => template.filename !== 'app-component.mjs');
|
|
129
|
+
app.templates.push({ src: join(runtimeDir, 'app-component.mjs'), filename: 'app-component.mjs' });
|
|
130
|
+
});
|
|
131
|
+
nuxt.hook('imports:sources', (presets) => {
|
|
132
|
+
const polyfills = ['requestIdleCallback', 'cancelIdleCallback'];
|
|
133
|
+
const stubbedComposables = ['useNuxtApp'];
|
|
134
|
+
for (const appPreset of presets.filter(p => p && typeof p === 'object' && 'from' in p && p.from?.startsWith('#app'))) {
|
|
135
|
+
if ('imports' in appPreset && Array.isArray(appPreset.imports)) {
|
|
136
|
+
appPreset.imports = appPreset.imports.filter(i => typeof i !== 'string' || (!stubbedComposables.includes(i) && !polyfills.includes(i)));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
presets.push({
|
|
140
|
+
from: '#build/poveste/composables.mjs',
|
|
141
|
+
imports: stubbedComposables,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
viteConfig: await new Promise((resolve, reject) => {
|
|
146
|
+
nuxt.hook('modules:done', () => {
|
|
147
|
+
nuxt.hook('components:extend', (components) => {
|
|
148
|
+
for (const name of ['NuxtLink']) {
|
|
149
|
+
Object.assign(components.find(c => c.pascalName === name) || {}, {
|
|
150
|
+
export: name,
|
|
151
|
+
filePath: '#build/poveste/components.mjs',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
nuxt.hook('vite:configResolved', (config, { isClient }) => {
|
|
156
|
+
if (isClient) {
|
|
157
|
+
resolve(config);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
nuxt.ready()
|
|
162
|
+
.then(() => buildNuxt(nuxt))
|
|
163
|
+
.catch((err) => {
|
|
164
|
+
if (!err.toString().includes('_stop_')) {
|
|
165
|
+
reject(err);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}),
|
|
169
|
+
nuxt,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createApp } from 'h3';
|
|
2
|
+
import { createFetch } from 'ofetch';
|
|
3
|
+
export async function setupNuxtApp(publicConfig) {
|
|
4
|
+
const win = window;
|
|
5
|
+
win.__NUXT__ = {
|
|
6
|
+
serverRendered: false,
|
|
7
|
+
config: {
|
|
8
|
+
public: { ...publicConfig },
|
|
9
|
+
app: { baseURL: '/' },
|
|
10
|
+
},
|
|
11
|
+
data: {},
|
|
12
|
+
state: {},
|
|
13
|
+
};
|
|
14
|
+
const app = win.document.createElement('div');
|
|
15
|
+
// this is a workaround for a happy-dom bug with ids beginning with _
|
|
16
|
+
app.id = 'nuxt-test';
|
|
17
|
+
win.document.body.appendChild(app);
|
|
18
|
+
win.IntersectionObserver
|
|
19
|
+
= win.IntersectionObserver
|
|
20
|
+
|| class IntersectionObserver {
|
|
21
|
+
observe() {
|
|
22
|
+
// noop
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const h3App = createApp();
|
|
26
|
+
const registry = new Set();
|
|
27
|
+
if (__HST_COLLECT__) {
|
|
28
|
+
const { toNodeListener, } = await import('h3');
|
|
29
|
+
const { createCall, createFetch: createLocalFetch, } = await import('unenv/runtime/fetch/index');
|
|
30
|
+
// @ts-expect-error TODO: fix in h3
|
|
31
|
+
const localCall = createCall(toNodeListener(h3App));
|
|
32
|
+
const localFetch = createLocalFetch(localCall, globalThis.fetch);
|
|
33
|
+
win.fetch = (init, options) => {
|
|
34
|
+
if (typeof init === 'string' && registry.has(init)) {
|
|
35
|
+
init = `/_${init}`;
|
|
36
|
+
}
|
|
37
|
+
return localFetch(init, options);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers });
|
|
41
|
+
win.__registry = registry;
|
|
42
|
+
win.__app = h3App;
|
|
43
|
+
// @ts-expect-error no types
|
|
44
|
+
const result = await import('#app/entry');
|
|
45
|
+
await result.default();
|
|
46
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@poveste/plugin-nuxt",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Poveste plugin to integrate with Nuxt 3",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Sorin Gitlan"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"url": "https://github.com/poveste-dev/poveste.git",
|
|
12
|
+
"type": "git",
|
|
13
|
+
"directory": "packages/poveste-plugin-nuxt"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./*": "./*"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"nuxt": "^3.0.0-rc.11",
|
|
27
|
+
"poveste": "^0.1.0",
|
|
28
|
+
"@poveste/plugin-vue": "^0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@nuxt/kit": "^3.14.1592",
|
|
32
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
33
|
+
"h3": "^1.13.0",
|
|
34
|
+
"ofetch": "^1.4.1",
|
|
35
|
+
"unenv": "^1.10.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@nuxt/schema": "^3.14.1592",
|
|
39
|
+
"@types/node": "^22.10.1",
|
|
40
|
+
"typescript": "5.6.3",
|
|
41
|
+
"vite": "^7.3.0",
|
|
42
|
+
"poveste": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rimraf dist && tsc -d",
|
|
46
|
+
"watch": "tsc -d -w --sourceMap"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const NuxtLink = defineComponent({
|
|
4
|
+
name: 'NuxtLink',
|
|
5
|
+
props: {
|
|
6
|
+
to: [String, Object],
|
|
7
|
+
},
|
|
8
|
+
setup(props, ctx) {
|
|
9
|
+
return () => h('a', {
|
|
10
|
+
href: typeof props.to === 'string' ? props.to : '#',
|
|
11
|
+
...ctx.attrs,
|
|
12
|
+
}, [ctx.slots.default?.()])
|
|
13
|
+
},
|
|
14
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const useNuxtApp = () => ({ runWithContext: async fn => await fn() })
|
package/src/global.d.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { Nuxt } from '@nuxt/schema'
|
|
2
|
+
import type { Plugin } from 'poveste'
|
|
3
|
+
import type { UserConfig as ViteConfig } from 'vite'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import replace from '@rollup/plugin-replace'
|
|
7
|
+
|
|
8
|
+
const ignorePlugins = [
|
|
9
|
+
'nuxt:vite-node-server',
|
|
10
|
+
'nuxt:dev-style-ssr',
|
|
11
|
+
'nuxt:vite-relative-asset',
|
|
12
|
+
'nuxt:cache-dir',
|
|
13
|
+
'nuxt:dynamic-base-path',
|
|
14
|
+
'nuxt:import-protection',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
export function HstNuxt(): Plugin {
|
|
18
|
+
let nuxt: Nuxt
|
|
19
|
+
return {
|
|
20
|
+
name: '@poveste/plugin-nuxt',
|
|
21
|
+
|
|
22
|
+
async defaultConfig() {
|
|
23
|
+
const nuxtViteConfig = await useNuxtViteConfig()
|
|
24
|
+
const { viteConfig } = nuxtViteConfig
|
|
25
|
+
|
|
26
|
+
nuxt = nuxtViteConfig.nuxt // We save it to close it later
|
|
27
|
+
const plugins = viteConfig.plugins.filter((p: any) => !ignorePlugins.includes(p?.name))
|
|
28
|
+
return {
|
|
29
|
+
vite: {
|
|
30
|
+
server: {
|
|
31
|
+
watch: viteConfig.server.watch,
|
|
32
|
+
fs: {
|
|
33
|
+
allow: viteConfig.server.fs.allow,
|
|
34
|
+
},
|
|
35
|
+
middlewareMode: false,
|
|
36
|
+
},
|
|
37
|
+
define: {
|
|
38
|
+
...viteConfig.define,
|
|
39
|
+
'process.server': false,
|
|
40
|
+
'process.client': true,
|
|
41
|
+
'process.browser': true,
|
|
42
|
+
'process.nitro': false,
|
|
43
|
+
'process.prerender': false,
|
|
44
|
+
},
|
|
45
|
+
resolve: {
|
|
46
|
+
alias: viteConfig.resolve.alias,
|
|
47
|
+
extensions: viteConfig.resolve.extensions,
|
|
48
|
+
dedupe: viteConfig.resolve.dedupe,
|
|
49
|
+
},
|
|
50
|
+
plugins: [
|
|
51
|
+
...plugins,
|
|
52
|
+
replace({
|
|
53
|
+
values: {
|
|
54
|
+
'import.meta.server': 'false',
|
|
55
|
+
'import.meta.client': 'true',
|
|
56
|
+
},
|
|
57
|
+
preventAssignment: true,
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
css: viteConfig.css,
|
|
61
|
+
publicDir: viteConfig.publicDir,
|
|
62
|
+
optimizeDeps: {
|
|
63
|
+
...viteConfig.optimizeDeps,
|
|
64
|
+
exclude: [
|
|
65
|
+
...viteConfig.optimizeDeps.exclude,
|
|
66
|
+
'@poveste/plugin-nuxt',
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
// @ts-expect-error Vue-specific config
|
|
70
|
+
vue: viteConfig.vue,
|
|
71
|
+
logLevel: 'info',
|
|
72
|
+
},
|
|
73
|
+
setupCode: [
|
|
74
|
+
`${nuxt.options.css.map(file => `import '${file}'`).join('\n')}`,
|
|
75
|
+
`import { setupNuxtApp } from '@poveste/plugin-nuxt/dist/runtime/app-setup.js'
|
|
76
|
+
export async function setupVue3 () {
|
|
77
|
+
await setupNuxtApp(${JSON.stringify(nuxt.options.runtimeConfig.public)})
|
|
78
|
+
}`,
|
|
79
|
+
],
|
|
80
|
+
viteNodeInlineDeps: [
|
|
81
|
+
/\/(nuxt|nuxt3)\//,
|
|
82
|
+
/^#/,
|
|
83
|
+
/\.nuxt/,
|
|
84
|
+
...(nuxt.options.build.transpile.filter(
|
|
85
|
+
r => typeof r === 'string' || r instanceof RegExp,
|
|
86
|
+
) as Array<string | RegExp>),
|
|
87
|
+
],
|
|
88
|
+
build: {
|
|
89
|
+
excludeFromVendorsChunk: [
|
|
90
|
+
/nuxt\/dist\/app/,
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
onDev(api, onCleanup) {
|
|
97
|
+
onCleanup(async () => {
|
|
98
|
+
nuxt?.close()
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
onBuild(api) {
|
|
103
|
+
api.onBuildEnd(() => {
|
|
104
|
+
nuxt?.close()
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
onPreview() {
|
|
109
|
+
nuxt?.close()
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function useNuxtViteConfig() {
|
|
115
|
+
const { loadNuxt, buildNuxt } = await import('@nuxt/kit')
|
|
116
|
+
const nuxt = await loadNuxt({
|
|
117
|
+
// cwd: process.cwd(),
|
|
118
|
+
ready: false,
|
|
119
|
+
dev: true,
|
|
120
|
+
overrides: {
|
|
121
|
+
devtools: { enabled: false },
|
|
122
|
+
ssr: false,
|
|
123
|
+
experimental: {
|
|
124
|
+
appManifest: false,
|
|
125
|
+
},
|
|
126
|
+
app: {
|
|
127
|
+
rootId: 'nuxt-test',
|
|
128
|
+
},
|
|
129
|
+
pages: false,
|
|
130
|
+
typescript: {
|
|
131
|
+
typeCheck: false,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
if (nuxt.options.builder as string !== '@nuxt/vite-builder') {
|
|
136
|
+
throw new Error(`Poveste only supports Vite bundler, but Nuxt builder is currently set to '${nuxt.options.builder}'.`)
|
|
137
|
+
}
|
|
138
|
+
const runtimeDir = fileURLToPath(new URL('../runtime', import.meta.url))
|
|
139
|
+
nuxt.options.build.templates.push(
|
|
140
|
+
{ src: join(runtimeDir, 'composables.mjs'), filename: 'poveste/composables.mjs' },
|
|
141
|
+
{ src: join(runtimeDir, 'components.mjs'), filename: 'poveste/components.mjs' },
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
nuxt.hook('app:templates', (app) => {
|
|
145
|
+
app.templates = app.templates.filter(template => template.filename !== 'app-component.mjs')
|
|
146
|
+
app.templates.push({ src: join(runtimeDir, 'app-component.mjs'), filename: 'app-component.mjs' })
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
nuxt.hook('imports:sources', (presets) => {
|
|
150
|
+
const polyfills = ['requestIdleCallback', 'cancelIdleCallback']
|
|
151
|
+
const stubbedComposables = ['useNuxtApp']
|
|
152
|
+
for (const appPreset of presets.filter(p => p && typeof p === 'object' && 'from' in p && p.from?.startsWith('#app'))) {
|
|
153
|
+
if ('imports' in appPreset && Array.isArray(appPreset.imports)) {
|
|
154
|
+
appPreset.imports = appPreset.imports.filter(i => typeof i !== 'string' || (!stubbedComposables.includes(i) && !polyfills.includes(i)))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
presets.push({
|
|
158
|
+
from: '#build/poveste/composables.mjs',
|
|
159
|
+
imports: stubbedComposables,
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
viteConfig: await new Promise<ViteConfig>((resolve, reject) => {
|
|
165
|
+
nuxt.hook('modules:done', () => {
|
|
166
|
+
nuxt.hook('components:extend', (components) => {
|
|
167
|
+
for (const name of ['NuxtLink']) {
|
|
168
|
+
Object.assign(components.find(c => c.pascalName === name) || {}, {
|
|
169
|
+
export: name,
|
|
170
|
+
filePath: '#build/poveste/components.mjs',
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
nuxt.hook('vite:configResolved', (config, { isClient }) => {
|
|
176
|
+
if (isClient) {
|
|
177
|
+
resolve(config as any)
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
nuxt.ready()
|
|
182
|
+
.then(() => buildNuxt(nuxt))
|
|
183
|
+
.catch((err) => {
|
|
184
|
+
if (!err.toString().includes('_stop_')) {
|
|
185
|
+
reject(err)
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
}),
|
|
189
|
+
nuxt,
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { PublicRuntimeConfig } from '@nuxt/schema'
|
|
2
|
+
import type { App } from 'h3'
|
|
3
|
+
import { createApp } from 'h3'
|
|
4
|
+
import { createFetch } from 'ofetch'
|
|
5
|
+
|
|
6
|
+
export async function setupNuxtApp(publicConfig: PublicRuntimeConfig) {
|
|
7
|
+
const win = window as unknown as Window & {
|
|
8
|
+
__app: App
|
|
9
|
+
__registry: Set<string>
|
|
10
|
+
__NUXT__: any
|
|
11
|
+
$fetch: any
|
|
12
|
+
fetch: any
|
|
13
|
+
IntersectionObserver: any
|
|
14
|
+
Headers: any
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
win.__NUXT__ = {
|
|
18
|
+
serverRendered: false,
|
|
19
|
+
config: {
|
|
20
|
+
public: { ...publicConfig },
|
|
21
|
+
app: { baseURL: '/' },
|
|
22
|
+
},
|
|
23
|
+
data: {},
|
|
24
|
+
state: {},
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const app = win.document.createElement('div')
|
|
28
|
+
// this is a workaround for a happy-dom bug with ids beginning with _
|
|
29
|
+
app.id = 'nuxt-test'
|
|
30
|
+
win.document.body.appendChild(app)
|
|
31
|
+
|
|
32
|
+
win.IntersectionObserver
|
|
33
|
+
= win.IntersectionObserver
|
|
34
|
+
|| class IntersectionObserver {
|
|
35
|
+
observe() {
|
|
36
|
+
// noop
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const h3App = createApp()
|
|
41
|
+
|
|
42
|
+
const registry = new Set<string>()
|
|
43
|
+
|
|
44
|
+
if (__HST_COLLECT__) {
|
|
45
|
+
const {
|
|
46
|
+
toNodeListener,
|
|
47
|
+
} = await import('h3')
|
|
48
|
+
const {
|
|
49
|
+
createCall,
|
|
50
|
+
createFetch: createLocalFetch,
|
|
51
|
+
} = await import('unenv/runtime/fetch/index')
|
|
52
|
+
// @ts-expect-error TODO: fix in h3
|
|
53
|
+
const localCall = createCall(toNodeListener(h3App))
|
|
54
|
+
const localFetch = createLocalFetch(localCall, globalThis.fetch)
|
|
55
|
+
|
|
56
|
+
win.fetch = (init: string, options?: any) => {
|
|
57
|
+
if (typeof init === 'string' && registry.has(init)) {
|
|
58
|
+
init = `/_${init}`
|
|
59
|
+
}
|
|
60
|
+
return localFetch(init, options)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers as any })
|
|
65
|
+
|
|
66
|
+
win.__registry = registry
|
|
67
|
+
win.__app = h3App
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error no types
|
|
70
|
+
const result = await import('#app/entry')
|
|
71
|
+
await result.default()
|
|
72
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
// Volar
|
|
5
|
+
"jsx": "preserve",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ESNext",
|
|
8
|
+
"DOM"
|
|
9
|
+
],
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"module": "ESNext",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"types": [
|
|
15
|
+
"node"
|
|
16
|
+
],
|
|
17
|
+
"strictBindCallApply": true,
|
|
18
|
+
"strictFunctionTypes": true,
|
|
19
|
+
"alwaysStrict": true,
|
|
20
|
+
// Strict
|
|
21
|
+
"noImplicitAny": false,
|
|
22
|
+
"noImplicitThis": true,
|
|
23
|
+
"outDir": "dist",
|
|
24
|
+
"removeComments": false,
|
|
25
|
+
"sourceMap": false,
|
|
26
|
+
"allowSyntheticDefaultImports": true,
|
|
27
|
+
"esModuleInterop": true,
|
|
28
|
+
"skipLibCheck": true,
|
|
29
|
+
"preserveWatchOutput": true
|
|
30
|
+
},
|
|
31
|
+
"include": [
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"exclude": [
|
|
35
|
+
"node_modules",
|
|
36
|
+
"generated/**/*",
|
|
37
|
+
"dist/**/*",
|
|
38
|
+
"src/**/*.spec.ts"
|
|
39
|
+
]
|
|
40
|
+
}
|