@vueuse/nuxt 7.4.0 → 7.4.1
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/index.mjs +37 -29
- package/indexes.json +4 -1
- package/package.json +8 -8
- package/ssr-plugin.mjs +48 -0
package/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { dirname, resolve } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { isPackageExists } from 'local-pkg';
|
|
5
5
|
|
|
6
|
-
const _dirname =
|
|
6
|
+
const _dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const disabledFunctions = [
|
|
8
8
|
"useFetch",
|
|
9
9
|
"toRefs",
|
|
@@ -24,6 +24,7 @@ const packages = [
|
|
|
24
24
|
const fullPackages = packages.map((p) => `@vueuse/${p}`);
|
|
25
25
|
function VueUseModule() {
|
|
26
26
|
const { nuxt } = this;
|
|
27
|
+
const options = nuxt.options.vueuse || {};
|
|
27
28
|
nuxt.hook("vite:extend", ({ config }) => {
|
|
28
29
|
config.optimizeDeps = config.optimizeDeps || {};
|
|
29
30
|
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
@@ -33,36 +34,43 @@ function VueUseModule() {
|
|
|
33
34
|
nuxt.options.build.transpile = nuxt.options.build.transpile || [];
|
|
34
35
|
nuxt.options.build.transpile.push("@vueuse/nuxt", "@vueuse/core", "@vueuse/shared");
|
|
35
36
|
let indexes;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
if (options.ssrHandlers) {
|
|
38
|
+
const pluginPath = resolve(_dirname, "./ssr-plugin.mjs");
|
|
39
|
+
nuxt.options.plugins = nuxt.options.plugins || [];
|
|
40
|
+
nuxt.options.plugins.push(pluginPath);
|
|
41
|
+
}
|
|
42
|
+
if (options.autoImports !== false) {
|
|
43
|
+
nuxt.hook("autoImports:sources", (sources) => {
|
|
44
|
+
if (sources.find((i) => fullPackages.includes(i.from)))
|
|
45
|
+
return;
|
|
46
|
+
if (!indexes) {
|
|
47
|
+
try {
|
|
48
|
+
indexes = JSON.parse(fs.readFileSync(resolve(_dirname, "./indexes.json"), "utf-8"));
|
|
49
|
+
indexes == null ? void 0 : indexes.functions.forEach((i) => {
|
|
50
|
+
if (i.package === "shared")
|
|
51
|
+
i.package = "core";
|
|
52
|
+
});
|
|
53
|
+
} catch (e) {
|
|
54
|
+
throw new Error("[@vueuse/nuxt] Failed to load indexes.json");
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
57
|
+
if (!indexes)
|
|
58
|
+
return;
|
|
59
|
+
for (const pkg of packages) {
|
|
60
|
+
if (pkg === "shared")
|
|
61
|
+
continue;
|
|
62
|
+
if (!isPackageExists(`@vueuse/${pkg}`))
|
|
63
|
+
continue;
|
|
64
|
+
const functions = indexes.functions.filter((i) => (i.package === "core" || i.package === "shared") && !i.internal);
|
|
65
|
+
if (functions.length) {
|
|
66
|
+
sources.push({
|
|
67
|
+
from: `@vueuse/${pkg}`,
|
|
68
|
+
names: indexes.functions.filter((i) => i.package === pkg && !i.internal).map((i) => i.name).filter((i) => i.length >= 4 && !disabledFunctions.includes(i))
|
|
69
|
+
});
|
|
70
|
+
}
|
|
63
71
|
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
export { VueUseModule as default };
|
package/indexes.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/nuxt",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.1",
|
|
4
4
|
"description": "VueUse Nuxt Module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"nuxt3",
|
|
10
10
|
"nuxt-module"
|
|
11
11
|
],
|
|
12
|
+
"homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/vueuse/vueuse/issues"
|
|
15
|
+
},
|
|
12
16
|
"license": "MIT",
|
|
13
17
|
"repository": {
|
|
14
18
|
"type": "git",
|
|
@@ -17,6 +21,7 @@
|
|
|
17
21
|
},
|
|
18
22
|
"funding": "https://github.com/sponsors/antfu",
|
|
19
23
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
24
|
+
"sideEffects": false,
|
|
20
25
|
"exports": {
|
|
21
26
|
".": {
|
|
22
27
|
"import": "./index.mjs",
|
|
@@ -26,15 +31,10 @@
|
|
|
26
31
|
"./*": "./*"
|
|
27
32
|
},
|
|
28
33
|
"main": "./index.cjs",
|
|
29
|
-
"types": "./index.d.ts",
|
|
30
34
|
"module": "./index.mjs",
|
|
31
|
-
"
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/vueuse/vueuse/issues"
|
|
34
|
-
},
|
|
35
|
-
"homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme",
|
|
35
|
+
"types": "./index.d.ts",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@vueuse/core": "7.4.
|
|
37
|
+
"@vueuse/core": "7.4.1",
|
|
38
38
|
"local-pkg": "^0.4.0",
|
|
39
39
|
"vue-demi": "*"
|
|
40
40
|
}
|
package/ssr-plugin.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { setSSRHandler } from '@vueuse/core'
|
|
2
|
+
import { useMeta } from '#meta'
|
|
3
|
+
import { useCookie } from '#app'
|
|
4
|
+
|
|
5
|
+
setSSRHandler('getDefaultStorage', () => {
|
|
6
|
+
const cookieMap = new Map()
|
|
7
|
+
return {
|
|
8
|
+
getItem: (key) => {
|
|
9
|
+
if (!cookieMap.get(key))
|
|
10
|
+
cookieMap.set(key, useCookie(key))
|
|
11
|
+
return cookieMap.get(key).value
|
|
12
|
+
},
|
|
13
|
+
setItem: (key, value) => {
|
|
14
|
+
if (!cookieMap.get(key))
|
|
15
|
+
cookieMap.set(key, useCookie(key))
|
|
16
|
+
cookieMap.get(key).value = value
|
|
17
|
+
},
|
|
18
|
+
removeItem: (key) => {
|
|
19
|
+
if (!cookieMap.get(key))
|
|
20
|
+
cookieMap.set(key, useCookie(key))
|
|
21
|
+
cookieMap.get(key).value = undefined
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if (process.server) {
|
|
27
|
+
setSSRHandler('updateHTMLAttrs', (selector, attr, value) => {
|
|
28
|
+
if (selector === 'html') {
|
|
29
|
+
useMeta({
|
|
30
|
+
htmlAttrs: {
|
|
31
|
+
[attr]: value,
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
else if (selector === 'body') {
|
|
36
|
+
useMeta({
|
|
37
|
+
bodyAttrs: {
|
|
38
|
+
[attr]: value,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`Unsupported meta selector "${selector}" in SSR`)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default () => {}
|