@nuxtjs/prismic 3.0.3 → 3.1.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/README.md +15 -6
- package/dist/module.d.mts +80 -1
- package/dist/module.d.ts +80 -1
- package/dist/module.json +2 -2
- package/dist/module.mjs +15 -13
- package/dist/runtime/plugin.mjs +10 -4
- package/dist/types.d.mts +3 -2
- package/dist/types.d.ts +3 -2
- package/package.json +11 -11
- package/src/module.ts +41 -29
- package/src/runtime/plugin.client.ts +1 -1
- package/src/runtime/plugin.ts +14 -8
- package/src/types.ts +81 -2
package/README.md
CHANGED
|
@@ -19,17 +19,27 @@ Replace all on all files (README.md, CONTRIBUTING.md, bug_report.md, package.jso
|
|
|
19
19
|
|
|
20
20
|
Easily connect your Nuxt.js application to your content hosted on [Prismic][prismic].
|
|
21
21
|
|
|
22
|
+
- [✨ Release Notes][changelog]
|
|
23
|
+
- [🏀 Online Playground][playground]
|
|
24
|
+
- [📖 Module Documentation][nuxt-docs]
|
|
25
|
+
- [📚 Prismic Documentation][prismic-docs]
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
<!-- Highlight some of the features your module provide here -->
|
|
22
30
|
- 🚀 Add Prismic to your Nuxt app in seconds;
|
|
23
31
|
- 🎣 Access Prismic SDK through composition and options API;
|
|
24
32
|
- 🖼 Prismic previews supported.
|
|
25
33
|
|
|
26
|
-
##
|
|
34
|
+
## Quick Setup
|
|
35
|
+
|
|
36
|
+
Install the module to your Nuxt application with one command:
|
|
27
37
|
|
|
28
38
|
```bash
|
|
29
|
-
|
|
39
|
+
npx nuxi module add prismic
|
|
30
40
|
```
|
|
31
41
|
|
|
32
|
-
Then,
|
|
42
|
+
Then, configure your Prismic API endpoint:
|
|
33
43
|
|
|
34
44
|
```javascript
|
|
35
45
|
import { defineNuxtConfig } from 'nuxt'
|
|
@@ -42,9 +52,7 @@ export default defineNuxtConfig({
|
|
|
42
52
|
});
|
|
43
53
|
```
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
To discover what's new on this package check out [the changelog][changelog]. For full documentation, visit the [module documentation][nuxt-docs] and [Prismic official documentation][prismic-docs].
|
|
55
|
+
That's it! You can now use Prismic in your Nuxt app ✨
|
|
48
56
|
|
|
49
57
|
## Contributing
|
|
50
58
|
|
|
@@ -68,6 +76,7 @@ Whether you're helping us fix bugs, improve the docs, or spread the word, we'd l
|
|
|
68
76
|
|
|
69
77
|
<!-- TODO: Replace link with a more useful one if available -->
|
|
70
78
|
|
|
79
|
+
[playground]: https://stackblitz.com/github/nuxt-modules/prismic/tree/master/examples/minimal?file=pages%2Findex.vue
|
|
71
80
|
[nuxt-docs]: https://prismic.nuxtjs.org
|
|
72
81
|
[prismic-docs]: https://prismic.io/docs/technical-reference/prismicio-vue?version=v4
|
|
73
82
|
[changelog]: ./CHANGELOG.md
|
package/dist/module.d.mts
CHANGED
|
@@ -1,17 +1,96 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { PrismicPluginOptions } from '@prismicio/vue';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* `@nuxtjs/prismic` module options.
|
|
6
|
+
*
|
|
7
|
+
* @see Module documentation: {@link https://prismic.nuxtjs.org}
|
|
8
|
+
* @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
|
|
9
|
+
*/
|
|
4
10
|
type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'client' | 'linkResolver' | 'htmlSerializer' | 'richTextSerializer'> & {
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A Prismic repository endpoint to init the module's `@prismicio/client`
|
|
13
|
+
* instance used to fetch content from a Prismic repository with.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Said client will be used exposed through `this.$prismic.client` and
|
|
17
|
+
* `usePrismic().client`.
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```javascript
|
|
21
|
+
* // A repository ID
|
|
22
|
+
* "my-repo";
|
|
23
|
+
*
|
|
24
|
+
* //A full repository endpoint
|
|
25
|
+
* "https://my-repo.cdn.prismic.io/api/v2";
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
29
|
+
*/
|
|
30
|
+
endpoint?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The Prismic environment in use by Slice Machine configured through
|
|
33
|
+
* environment variables.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `endpoint` value.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
environment?: string;
|
|
40
|
+
/**
|
|
41
|
+
* An optional path to a file exporting a `@prismicio/client` instance used
|
|
42
|
+
* to fetch content from a Prismic repository to configure the module with.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Said client will be used exposed through `this.$prismic.client` and
|
|
46
|
+
* `usePrismic().client`.
|
|
47
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
48
|
+
*/
|
|
6
49
|
client?: string;
|
|
50
|
+
/**
|
|
51
|
+
* An optional path to a file exporting a link resolver function used to
|
|
52
|
+
* resolve links to Prismic documents when not using the route resolver
|
|
53
|
+
* parameter with `@prismicio/client`.
|
|
54
|
+
*
|
|
55
|
+
* @see Link resolver documentation {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
56
|
+
*/
|
|
7
57
|
linkResolver?: string;
|
|
58
|
+
/**
|
|
59
|
+
* An optional path to a file exporting an HTML serializer to customize
|
|
60
|
+
* the way rich text fields are rendered.
|
|
61
|
+
*
|
|
62
|
+
* @see HTML serializer documentation {@link https://prismic.io/docs/rich-text}
|
|
63
|
+
*/
|
|
8
64
|
richTextSerializer?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Desired path of the preview page used by Prismic to enter preview
|
|
67
|
+
* session.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* `false` can be used to disable the preview page.
|
|
71
|
+
*
|
|
72
|
+
* @defaultValue `"/preview"`
|
|
73
|
+
*/
|
|
9
74
|
preview?: string | false;
|
|
75
|
+
/**
|
|
76
|
+
* Whether or not to inject Prismic toolbar script.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* The toolbar script is required for previews to work.
|
|
80
|
+
*
|
|
81
|
+
* @defaultValue `true`
|
|
82
|
+
*/
|
|
10
83
|
toolbar?: boolean;
|
|
11
84
|
};
|
|
12
85
|
|
|
13
86
|
declare module '@nuxt/schema' {
|
|
14
87
|
interface PublicRuntimeConfig {
|
|
88
|
+
/**
|
|
89
|
+
* `@nuxtjs/prismic` module options.
|
|
90
|
+
*
|
|
91
|
+
* @see Module documentation: {@link https://prismic.nuxtjs.org}
|
|
92
|
+
* @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
|
|
93
|
+
*/
|
|
15
94
|
prismic: PrismicModuleOptions;
|
|
16
95
|
}
|
|
17
96
|
}
|
package/dist/module.d.ts
CHANGED
|
@@ -1,17 +1,96 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { PrismicPluginOptions } from '@prismicio/vue';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* `@nuxtjs/prismic` module options.
|
|
6
|
+
*
|
|
7
|
+
* @see Module documentation: {@link https://prismic.nuxtjs.org}
|
|
8
|
+
* @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
|
|
9
|
+
*/
|
|
4
10
|
type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'client' | 'linkResolver' | 'htmlSerializer' | 'richTextSerializer'> & {
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A Prismic repository endpoint to init the module's `@prismicio/client`
|
|
13
|
+
* instance used to fetch content from a Prismic repository with.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Said client will be used exposed through `this.$prismic.client` and
|
|
17
|
+
* `usePrismic().client`.
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```javascript
|
|
21
|
+
* // A repository ID
|
|
22
|
+
* "my-repo";
|
|
23
|
+
*
|
|
24
|
+
* //A full repository endpoint
|
|
25
|
+
* "https://my-repo.cdn.prismic.io/api/v2";
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
29
|
+
*/
|
|
30
|
+
endpoint?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The Prismic environment in use by Slice Machine configured through
|
|
33
|
+
* environment variables.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `endpoint` value.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
environment?: string;
|
|
40
|
+
/**
|
|
41
|
+
* An optional path to a file exporting a `@prismicio/client` instance used
|
|
42
|
+
* to fetch content from a Prismic repository to configure the module with.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Said client will be used exposed through `this.$prismic.client` and
|
|
46
|
+
* `usePrismic().client`.
|
|
47
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
48
|
+
*/
|
|
6
49
|
client?: string;
|
|
50
|
+
/**
|
|
51
|
+
* An optional path to a file exporting a link resolver function used to
|
|
52
|
+
* resolve links to Prismic documents when not using the route resolver
|
|
53
|
+
* parameter with `@prismicio/client`.
|
|
54
|
+
*
|
|
55
|
+
* @see Link resolver documentation {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
56
|
+
*/
|
|
7
57
|
linkResolver?: string;
|
|
58
|
+
/**
|
|
59
|
+
* An optional path to a file exporting an HTML serializer to customize
|
|
60
|
+
* the way rich text fields are rendered.
|
|
61
|
+
*
|
|
62
|
+
* @see HTML serializer documentation {@link https://prismic.io/docs/rich-text}
|
|
63
|
+
*/
|
|
8
64
|
richTextSerializer?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Desired path of the preview page used by Prismic to enter preview
|
|
67
|
+
* session.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* `false` can be used to disable the preview page.
|
|
71
|
+
*
|
|
72
|
+
* @defaultValue `"/preview"`
|
|
73
|
+
*/
|
|
9
74
|
preview?: string | false;
|
|
75
|
+
/**
|
|
76
|
+
* Whether or not to inject Prismic toolbar script.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* The toolbar script is required for previews to work.
|
|
80
|
+
*
|
|
81
|
+
* @defaultValue `true`
|
|
82
|
+
*/
|
|
10
83
|
toolbar?: boolean;
|
|
11
84
|
};
|
|
12
85
|
|
|
13
86
|
declare module '@nuxt/schema' {
|
|
14
87
|
interface PublicRuntimeConfig {
|
|
88
|
+
/**
|
|
89
|
+
* `@nuxtjs/prismic` module options.
|
|
90
|
+
*
|
|
91
|
+
* @see Module documentation: {@link https://prismic.nuxtjs.org}
|
|
92
|
+
* @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
|
|
93
|
+
*/
|
|
15
94
|
prismic: PrismicModuleOptions;
|
|
16
95
|
}
|
|
17
96
|
}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -21,10 +21,11 @@ const module = defineNuxtModule({
|
|
|
21
21
|
meta: {
|
|
22
22
|
name: "@nuxtjs/prismic",
|
|
23
23
|
configKey: "prismic",
|
|
24
|
-
compatibility: { nuxt: "^3.
|
|
24
|
+
compatibility: { nuxt: "^3.7.0" }
|
|
25
25
|
},
|
|
26
26
|
defaults: (nuxt) => ({
|
|
27
27
|
endpoint: "",
|
|
28
|
+
environment: "",
|
|
28
29
|
clientConfig: {},
|
|
29
30
|
client: "~/app/prismic/client",
|
|
30
31
|
linkResolver: "~/app/prismic/linkResolver",
|
|
@@ -36,19 +37,9 @@ const module = defineNuxtModule({
|
|
|
36
37
|
}),
|
|
37
38
|
hooks: {},
|
|
38
39
|
setup(options, nuxt) {
|
|
39
|
-
|
|
40
|
-
(_a = nuxt.options.runtimeConfig).public || (_a.public = {});
|
|
40
|
+
nuxt.options.runtimeConfig.public ||= {};
|
|
41
41
|
const moduleOptions = defu(nuxt.options.runtimeConfig.public.prismic, options);
|
|
42
42
|
nuxt.options.runtimeConfig.public.prismic = moduleOptions;
|
|
43
|
-
if (!moduleOptions.endpoint) {
|
|
44
|
-
logger.warn("Options `endpoint` is required, disabling module...");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const resolver = createResolver(import.meta.url);
|
|
48
|
-
nuxt.options.build.transpile.push(resolver.resolve("runtime"), "@nuxtjs/prismic", "@prismicio/vue");
|
|
49
|
-
(_b = nuxt.options.vite).optimizeDeps || (_b.optimizeDeps = {});
|
|
50
|
-
(_c = nuxt.options.vite.optimizeDeps).exclude || (_c.exclude = []);
|
|
51
|
-
nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue");
|
|
52
43
|
const proxyUserFileWithUndefinedFallback = (filename, path, extensions = ["js", "mjs", "ts"]) => {
|
|
53
44
|
const resolvedFilename = `prismic/proxy/${filename}.ts`;
|
|
54
45
|
const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
|
|
@@ -59,16 +50,27 @@ const module = defineNuxtModule({
|
|
|
59
50
|
filename: resolvedFilename,
|
|
60
51
|
getContents: () => `export { default } from '${path}'`
|
|
61
52
|
});
|
|
53
|
+
return true;
|
|
62
54
|
} else {
|
|
63
55
|
addTemplate({
|
|
64
56
|
filename: resolvedFilename,
|
|
65
57
|
getContents: () => "export default undefined"
|
|
66
58
|
});
|
|
59
|
+
return false;
|
|
67
60
|
}
|
|
68
61
|
};
|
|
69
|
-
proxyUserFileWithUndefinedFallback("client", moduleOptions.client);
|
|
62
|
+
const proxiedUserClient = proxyUserFileWithUndefinedFallback("client", moduleOptions.client);
|
|
63
|
+
if (!moduleOptions.endpoint && !proxiedUserClient && !process.env.NUXT_PUBLIC_PRISMIC_ENDPOINT) {
|
|
64
|
+
logger.warn(`\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
70
67
|
proxyUserFileWithUndefinedFallback("linkResolver", moduleOptions.linkResolver);
|
|
71
68
|
proxyUserFileWithUndefinedFallback("richTextSerializer", moduleOptions.richTextSerializer);
|
|
69
|
+
const resolver = createResolver(import.meta.url);
|
|
70
|
+
nuxt.options.build.transpile.push(resolver.resolve("runtime"), "@nuxtjs/prismic", "@prismicio/vue");
|
|
71
|
+
nuxt.options.vite.optimizeDeps ||= {};
|
|
72
|
+
nuxt.options.vite.optimizeDeps.exclude ||= [];
|
|
73
|
+
nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue");
|
|
72
74
|
addPlugin(resolver.resolve("runtime/plugin"));
|
|
73
75
|
addPlugin(resolver.resolve("runtime/plugin.client"));
|
|
74
76
|
if (moduleOptions.injectComponents) {
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -7,8 +7,10 @@ import linkResolver from "#build/prismic/proxy/linkResolver";
|
|
|
7
7
|
import richTextSerializer from "#build/prismic/proxy/richTextSerializer";
|
|
8
8
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
9
9
|
const options = useRuntimeConfig().public.prismic;
|
|
10
|
+
const endpoint = options.environment || options.endpoint || client?.endpoint || "";
|
|
10
11
|
const prismicPlugin = createPrismic({
|
|
11
12
|
...options,
|
|
13
|
+
endpoint,
|
|
12
14
|
client,
|
|
13
15
|
linkResolver,
|
|
14
16
|
richTextSerializer,
|
|
@@ -23,8 +25,11 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
23
25
|
nuxtApp.vueApp.use(prismicPlugin);
|
|
24
26
|
if (options.preview) {
|
|
25
27
|
const previewCookie = useCookie("io.prismic.preview").value;
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
+
if (import.meta.server) {
|
|
29
|
+
const req = useRequestEvent()?.node.req;
|
|
30
|
+
if (req) {
|
|
31
|
+
prismicPlugin.client.enableAutoPreviewsFromReq(req);
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
if (previewCookie) {
|
|
30
35
|
try {
|
|
@@ -47,13 +52,14 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
if (options.toolbar) {
|
|
50
|
-
const repositoryName = isRepositoryEndpoint(
|
|
55
|
+
const repositoryName = isRepositoryEndpoint(endpoint) ? getRepositoryName(endpoint) : endpoint;
|
|
51
56
|
useHead({
|
|
52
57
|
script: [{
|
|
53
58
|
key: "prismic-preview",
|
|
54
59
|
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
55
60
|
async: true,
|
|
56
|
-
defer: true
|
|
61
|
+
defer: true,
|
|
62
|
+
crossorigin: "anonymous"
|
|
57
63
|
}]
|
|
58
64
|
});
|
|
59
65
|
} else {
|
package/dist/types.d.mts
CHANGED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Easily connect your Nuxt 3 application to your content hosted on Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "nuxt-module-build",
|
|
36
|
+
"build": "nuxt-module-build build",
|
|
37
37
|
"dev": "nuxi dev playground",
|
|
38
38
|
"dev:build": "nuxi build playground",
|
|
39
39
|
"dev:preview": "nuxi preview playground",
|
|
@@ -50,22 +50,22 @@
|
|
|
50
50
|
"unit:watch": "vitest watch"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@nuxt/kit": "^3.
|
|
54
|
-
"@prismicio/client": "^7.
|
|
53
|
+
"@nuxt/kit": "^3.11.1",
|
|
54
|
+
"@prismicio/client": "^7.3.1",
|
|
55
55
|
"@prismicio/vue": "^4.1.0",
|
|
56
56
|
"consola": "^3.2.3",
|
|
57
|
-
"defu": "^6.1.
|
|
57
|
+
"defu": "^6.1.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@nuxt/module-builder": "^0.5.
|
|
60
|
+
"@nuxt/module-builder": "^0.5.5",
|
|
61
61
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
62
|
-
"@vitest/coverage-v8": "^
|
|
63
|
-
"eslint": "^8.
|
|
62
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
63
|
+
"eslint": "^8.57.0",
|
|
64
64
|
"mock-fs": "^5.2.0",
|
|
65
|
-
"nuxt": "^3.
|
|
65
|
+
"nuxt": "^3.11.1",
|
|
66
66
|
"standard-version": "^9.5.0",
|
|
67
|
-
"typescript": "^5.
|
|
68
|
-
"vitest": "^
|
|
67
|
+
"typescript": "^5.4.3",
|
|
68
|
+
"vitest": "^1.4.0"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=16.10.0"
|
package/src/module.ts
CHANGED
|
@@ -21,6 +21,12 @@ export type { PrismicModuleOptions } from './types'
|
|
|
21
21
|
|
|
22
22
|
declare module '@nuxt/schema' {
|
|
23
23
|
interface PublicRuntimeConfig {
|
|
24
|
+
/**
|
|
25
|
+
* `@nuxtjs/prismic` module options.
|
|
26
|
+
*
|
|
27
|
+
* @see Module documentation: {@link https://prismic.nuxtjs.org}
|
|
28
|
+
* @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
|
|
29
|
+
*/
|
|
24
30
|
prismic: PrismicModuleOptions
|
|
25
31
|
}
|
|
26
32
|
}
|
|
@@ -30,10 +36,11 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
30
36
|
meta: {
|
|
31
37
|
name: '@nuxtjs/prismic',
|
|
32
38
|
configKey: 'prismic',
|
|
33
|
-
compatibility: { nuxt: '^3.
|
|
39
|
+
compatibility: { nuxt: '^3.7.0' }
|
|
34
40
|
},
|
|
35
41
|
defaults: nuxt => ({
|
|
36
42
|
endpoint: '',
|
|
43
|
+
environment: '',
|
|
37
44
|
clientConfig: {},
|
|
38
45
|
client: '~/app/prismic/client',
|
|
39
46
|
linkResolver: '~/app/prismic/linkResolver',
|
|
@@ -50,44 +57,49 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
50
57
|
const moduleOptions: PrismicModuleOptions = defu(nuxt.options.runtimeConfig.public.prismic, options)
|
|
51
58
|
nuxt.options.runtimeConfig.public.prismic = moduleOptions
|
|
52
59
|
|
|
53
|
-
if (!moduleOptions.endpoint) {
|
|
54
|
-
logger.warn('Options `endpoint` is required, disabling module...')
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Runtime dir boilerplate
|
|
59
|
-
const resolver = createResolver(import.meta.url)
|
|
60
|
-
nuxt.options.build.transpile.push(resolver.resolve('runtime'), '@nuxtjs/prismic', '@prismicio/vue')
|
|
61
|
-
nuxt.options.vite.optimizeDeps ||= {}
|
|
62
|
-
nuxt.options.vite.optimizeDeps.exclude ||= []
|
|
63
|
-
nuxt.options.vite.optimizeDeps.exclude.push('@prismicio/vue')
|
|
64
|
-
|
|
65
60
|
// Add runtime user code
|
|
66
|
-
const proxyUserFileWithUndefinedFallback =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
const proxyUserFileWithUndefinedFallback =
|
|
62
|
+
(filename: string, path: string, extensions = ['js', 'mjs', 'ts']): boolean => {
|
|
63
|
+
const resolvedFilename = `prismic/proxy/${filename}.ts`
|
|
64
|
+
const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir)
|
|
65
|
+
const maybeUserFile = fileExists(resolvedPath, extensions)
|
|
70
66
|
|
|
71
|
-
|
|
67
|
+
if (maybeUserFile) {
|
|
72
68
|
// If user file exists, proxy it with vfs
|
|
73
|
-
|
|
69
|
+
logger.info(`Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, '~').replace(nuxt.options.rootDir, '~~').replace(/\\/g, '/')}\``)
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
addTemplate({
|
|
72
|
+
filename: resolvedFilename,
|
|
73
|
+
getContents: () => `export { default } from '${path}'`
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return true
|
|
77
|
+
} else {
|
|
80
78
|
// Else provide `undefined` fallback
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
addTemplate({
|
|
80
|
+
filename: resolvedFilename,
|
|
81
|
+
getContents: () => 'export default undefined'
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
85
86
|
}
|
|
87
|
+
|
|
88
|
+
const proxiedUserClient = proxyUserFileWithUndefinedFallback('client', moduleOptions.client!)
|
|
89
|
+
if (!moduleOptions.endpoint && !proxiedUserClient && !process.env.NUXT_PUBLIC_PRISMIC_ENDPOINT) {
|
|
90
|
+
logger.warn(`\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`)
|
|
91
|
+
return
|
|
86
92
|
}
|
|
87
|
-
proxyUserFileWithUndefinedFallback('client', moduleOptions.client!)
|
|
88
93
|
proxyUserFileWithUndefinedFallback('linkResolver', moduleOptions.linkResolver!)
|
|
89
94
|
proxyUserFileWithUndefinedFallback('richTextSerializer', moduleOptions.richTextSerializer!)
|
|
90
95
|
|
|
96
|
+
// Runtime dir boilerplate
|
|
97
|
+
const resolver = createResolver(import.meta.url)
|
|
98
|
+
nuxt.options.build.transpile.push(resolver.resolve('runtime'), '@nuxtjs/prismic', '@prismicio/vue')
|
|
99
|
+
nuxt.options.vite.optimizeDeps ||= {}
|
|
100
|
+
nuxt.options.vite.optimizeDeps.exclude ||= []
|
|
101
|
+
nuxt.options.vite.optimizeDeps.exclude.push('@prismicio/vue')
|
|
102
|
+
|
|
91
103
|
// Add plugin
|
|
92
104
|
addPlugin(resolver.resolve('runtime/plugin'))
|
|
93
105
|
addPlugin(resolver.resolve('runtime/plugin.client'))
|
package/src/runtime/plugin.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client'
|
|
1
|
+
import { isRepositoryEndpoint, getRepositoryName, type Client } from '@prismicio/client'
|
|
2
2
|
import { createPrismic } from '@prismicio/vue'
|
|
3
3
|
|
|
4
|
-
import { PrismicModuleOptions } from '../types'
|
|
5
4
|
import NuxtLink from '#app/components/nuxt-link'
|
|
5
|
+
import type { PrismicModuleOptions } from '../types'
|
|
6
6
|
import { defineNuxtPlugin, useCookie, useRequestEvent, onNuxtReady, refreshNuxtData, useHead, useRuntimeConfig, useRouter } from '#imports'
|
|
7
7
|
|
|
8
8
|
// @ts-expect-error vfs cannot be resolved here
|
|
@@ -14,9 +14,11 @@ import richTextSerializer from '#build/prismic/proxy/richTextSerializer'
|
|
|
14
14
|
|
|
15
15
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
16
16
|
const options: PrismicModuleOptions = useRuntimeConfig().public.prismic
|
|
17
|
+
const endpoint = options.environment || options.endpoint || (client as Client | undefined)?.endpoint || ''
|
|
17
18
|
|
|
18
19
|
const prismicPlugin = createPrismic({
|
|
19
20
|
...options,
|
|
21
|
+
endpoint,
|
|
20
22
|
client,
|
|
21
23
|
linkResolver,
|
|
22
24
|
richTextSerializer,
|
|
@@ -34,8 +36,11 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
34
36
|
const previewCookie = useCookie('io.prismic.preview').value
|
|
35
37
|
|
|
36
38
|
// Update client with req when running server side
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
+
if (import.meta.server) {
|
|
40
|
+
const req = useRequestEvent()?.node.req
|
|
41
|
+
if (req) {
|
|
42
|
+
prismicPlugin.client.enableAutoPreviewsFromReq(req)
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
if (previewCookie) {
|
|
@@ -69,16 +74,17 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
69
74
|
|
|
70
75
|
if (options.toolbar) {
|
|
71
76
|
// Add toolbar
|
|
72
|
-
const repositoryName = isRepositoryEndpoint(
|
|
73
|
-
? getRepositoryName(
|
|
74
|
-
:
|
|
77
|
+
const repositoryName = isRepositoryEndpoint(endpoint)
|
|
78
|
+
? getRepositoryName(endpoint)
|
|
79
|
+
: endpoint
|
|
75
80
|
|
|
76
81
|
useHead({
|
|
77
82
|
script: [{
|
|
78
83
|
key: 'prismic-preview',
|
|
79
84
|
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
80
85
|
async: true,
|
|
81
|
-
defer: true
|
|
86
|
+
defer: true,
|
|
87
|
+
crossorigin: 'anonymous'
|
|
82
88
|
}]
|
|
83
89
|
})
|
|
84
90
|
} else {
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,89 @@
|
|
|
1
|
-
import { PrismicPluginOptions } from '@prismicio/vue'
|
|
1
|
+
import type { PrismicPluginOptions } from '@prismicio/vue'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* `@nuxtjs/prismic` module options.
|
|
5
|
+
*
|
|
6
|
+
* @see Module documentation: {@link https://prismic.nuxtjs.org}
|
|
7
|
+
* @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
|
|
8
|
+
*/
|
|
3
9
|
export type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'client' | 'linkResolver' | 'htmlSerializer' | 'richTextSerializer'> & {
|
|
4
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A Prismic repository endpoint to init the module's `@prismicio/client`
|
|
12
|
+
* instance used to fetch content from a Prismic repository with.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Said client will be used exposed through `this.$prismic.client` and
|
|
16
|
+
* `usePrismic().client`.
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```javascript
|
|
20
|
+
* // A repository ID
|
|
21
|
+
* "my-repo";
|
|
22
|
+
*
|
|
23
|
+
* //A full repository endpoint
|
|
24
|
+
* "https://my-repo.cdn.prismic.io/api/v2";
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
28
|
+
*/
|
|
29
|
+
endpoint?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The Prismic environment in use by Slice Machine configured through
|
|
33
|
+
* environment variables.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `endpoint` value.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
environment?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An optional path to a file exporting a `@prismicio/client` instance used
|
|
43
|
+
* to fetch content from a Prismic repository to configure the module with.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* Said client will be used exposed through `this.$prismic.client` and
|
|
47
|
+
* `usePrismic().client`.
|
|
48
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
49
|
+
*/
|
|
5
50
|
client?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* An optional path to a file exporting a link resolver function used to
|
|
54
|
+
* resolve links to Prismic documents when not using the route resolver
|
|
55
|
+
* parameter with `@prismicio/client`.
|
|
56
|
+
*
|
|
57
|
+
* @see Link resolver documentation {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
58
|
+
*/
|
|
6
59
|
linkResolver?: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* An optional path to a file exporting an HTML serializer to customize
|
|
63
|
+
* the way rich text fields are rendered.
|
|
64
|
+
*
|
|
65
|
+
* @see HTML serializer documentation {@link https://prismic.io/docs/rich-text}
|
|
66
|
+
*/
|
|
7
67
|
richTextSerializer?: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Desired path of the preview page used by Prismic to enter preview
|
|
71
|
+
* session.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* `false` can be used to disable the preview page.
|
|
75
|
+
*
|
|
76
|
+
* @defaultValue `"/preview"`
|
|
77
|
+
*/
|
|
8
78
|
preview?: string | false;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether or not to inject Prismic toolbar script.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* The toolbar script is required for previews to work.
|
|
85
|
+
*
|
|
86
|
+
* @defaultValue `true`
|
|
87
|
+
*/
|
|
9
88
|
toolbar?: boolean;
|
|
10
89
|
};
|