@nuxtjs/prismic 3.0.3 → 3.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/dist/module.d.mts +80 -1
- package/dist/module.d.ts +80 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -10
- package/dist/runtime/plugin.mjs +3 -1
- package/package.json +9 -9
- package/src/module.ts +40 -28
- package/src/runtime/plugin.client.ts +1 -1
- package/src/runtime/plugin.ts +7 -5
- package/src/types.ts +81 -2
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
|
@@ -25,6 +25,7 @@ const module = defineNuxtModule({
|
|
|
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",
|
|
@@ -40,15 +41,6 @@ const module = defineNuxtModule({
|
|
|
40
41
|
(_a = nuxt.options.runtimeConfig).public || (_a.public = {});
|
|
41
42
|
const moduleOptions = defu(nuxt.options.runtimeConfig.public.prismic, options);
|
|
42
43
|
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
44
|
const proxyUserFileWithUndefinedFallback = (filename, path, extensions = ["js", "mjs", "ts"]) => {
|
|
53
45
|
const resolvedFilename = `prismic/proxy/${filename}.ts`;
|
|
54
46
|
const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
|
|
@@ -59,16 +51,27 @@ const module = defineNuxtModule({
|
|
|
59
51
|
filename: resolvedFilename,
|
|
60
52
|
getContents: () => `export { default } from '${path}'`
|
|
61
53
|
});
|
|
54
|
+
return true;
|
|
62
55
|
} else {
|
|
63
56
|
addTemplate({
|
|
64
57
|
filename: resolvedFilename,
|
|
65
58
|
getContents: () => "export default undefined"
|
|
66
59
|
});
|
|
60
|
+
return false;
|
|
67
61
|
}
|
|
68
62
|
};
|
|
69
|
-
proxyUserFileWithUndefinedFallback("client", moduleOptions.client);
|
|
63
|
+
const proxiedUserClient = proxyUserFileWithUndefinedFallback("client", moduleOptions.client);
|
|
64
|
+
if (!moduleOptions.endpoint && !proxiedUserClient && !process.env.NUXT_PUBLIC_PRISMIC_ENDPOINT) {
|
|
65
|
+
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...`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
70
68
|
proxyUserFileWithUndefinedFallback("linkResolver", moduleOptions.linkResolver);
|
|
71
69
|
proxyUserFileWithUndefinedFallback("richTextSerializer", moduleOptions.richTextSerializer);
|
|
70
|
+
const resolver = createResolver(import.meta.url);
|
|
71
|
+
nuxt.options.build.transpile.push(resolver.resolve("runtime"), "@nuxtjs/prismic", "@prismicio/vue");
|
|
72
|
+
(_b = nuxt.options.vite).optimizeDeps || (_b.optimizeDeps = {});
|
|
73
|
+
(_c = nuxt.options.vite.optimizeDeps).exclude || (_c.exclude = []);
|
|
74
|
+
nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue");
|
|
72
75
|
addPlugin(resolver.resolve("runtime/plugin"));
|
|
73
76
|
addPlugin(resolver.resolve("runtime/plugin.client"));
|
|
74
77
|
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,
|
|
@@ -47,7 +49,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
if (options.toolbar) {
|
|
50
|
-
const repositoryName = isRepositoryEndpoint(
|
|
52
|
+
const repositoryName = isRepositoryEndpoint(endpoint) ? getRepositoryName(endpoint) : endpoint;
|
|
51
53
|
useHead({
|
|
52
54
|
script: [{
|
|
53
55
|
key: "prismic-preview",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
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.8.0",
|
|
54
|
+
"@prismicio/client": "^7.3.1",
|
|
55
55
|
"@prismicio/vue": "^4.1.0",
|
|
56
56
|
"consola": "^3.2.3",
|
|
57
57
|
"defu": "^6.1.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@nuxt/module-builder": "^0.5.
|
|
60
|
+
"@nuxt/module-builder": "^0.5.2",
|
|
61
61
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
62
|
-
"@vitest/coverage-v8": "^0.34.
|
|
63
|
-
"eslint": "^8.
|
|
62
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
63
|
+
"eslint": "^8.52.0",
|
|
64
64
|
"mock-fs": "^5.2.0",
|
|
65
|
-
"nuxt": "^3.
|
|
65
|
+
"nuxt": "^3.8.0",
|
|
66
66
|
"standard-version": "^9.5.0",
|
|
67
67
|
"typescript": "^5.2.2",
|
|
68
|
-
"vitest": "^0.34.
|
|
68
|
+
"vitest": "^0.34.6"
|
|
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
|
}
|
|
@@ -34,6 +40,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
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,7 +1,7 @@
|
|
|
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'
|
|
4
|
+
import type { PrismicModuleOptions } from '../types'
|
|
5
5
|
import NuxtLink from '#app/components/nuxt-link'
|
|
6
6
|
import { defineNuxtPlugin, useCookie, useRequestEvent, onNuxtReady, refreshNuxtData, useHead, useRuntimeConfig, useRouter } from '#imports'
|
|
7
7
|
|
|
@@ -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,
|
|
@@ -69,9 +71,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
69
71
|
|
|
70
72
|
if (options.toolbar) {
|
|
71
73
|
// Add toolbar
|
|
72
|
-
const repositoryName = isRepositoryEndpoint(
|
|
73
|
-
? getRepositoryName(
|
|
74
|
-
:
|
|
74
|
+
const repositoryName = isRepositoryEndpoint(endpoint)
|
|
75
|
+
? getRepositoryName(endpoint)
|
|
76
|
+
: endpoint
|
|
75
77
|
|
|
76
78
|
useHead({
|
|
77
79
|
script: [{
|
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
|
};
|