@pinegrow/nuxt-module 3.0.0-beta.79 → 3.0.0-beta.80
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.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, addVitePlugin } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerPlugin, useNitro, addVitePlugin } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
@@ -9,7 +9,7 @@ const module = defineNuxtModule({
|
|
|
9
9
|
// Compatibility constraints
|
|
10
10
|
compatibility: {
|
|
11
11
|
// Semver version of supported nuxt versions
|
|
12
|
-
nuxt: "^3.
|
|
12
|
+
nuxt: "^3.1.0"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
// Default configuration options for your module
|
|
@@ -69,14 +69,19 @@ const module = defineNuxtModule({
|
|
|
69
69
|
hooks: {},
|
|
70
70
|
async setup(moduleOptions, nuxt) {
|
|
71
71
|
if (moduleOptions.liveDesigner) {
|
|
72
|
+
const { resolve } = createResolver(import.meta.url);
|
|
73
|
+
addServerPlugin(resolve("./runtime/nitro-plugin.mjs"));
|
|
72
74
|
const nuxtInstance = nuxt;
|
|
75
|
+
let pluginInstance;
|
|
73
76
|
nuxt.hook("listen", async (listenerServer) => {
|
|
74
77
|
try {
|
|
75
78
|
const { liveDesigner } = await import('./chunks/live-designer.mjs');
|
|
76
|
-
const
|
|
79
|
+
const nitroApp = useNitro();
|
|
80
|
+
pluginInstance = liveDesigner({
|
|
77
81
|
...moduleOptions.liveDesigner,
|
|
78
82
|
listenerServer,
|
|
79
|
-
nuxtInstance
|
|
83
|
+
nuxtInstance,
|
|
84
|
+
nitroApp
|
|
80
85
|
});
|
|
81
86
|
addVitePlugin(pluginInstance);
|
|
82
87
|
} catch (err) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { defineNitroPlugin } from 'nitropack/runtime/plugin'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
|
|
5
|
+
export default defineNitroPlugin(nitroApp => {
|
|
6
|
+
// const nitroInstance = nitroApp
|
|
7
|
+
|
|
8
|
+
nitroApp.hooks.hook('render:html', (html /*, { event }*/) => {
|
|
9
|
+
// console.log('render:html', html)
|
|
10
|
+
// html.bodyAppend.push('<hr>Appended by custom plugin')
|
|
11
|
+
|
|
12
|
+
const addons = [
|
|
13
|
+
{
|
|
14
|
+
name: 'pgia',
|
|
15
|
+
resources: [
|
|
16
|
+
{
|
|
17
|
+
parent: 'head',
|
|
18
|
+
parentResource: `public/pgia`, // relative to project root, must exists
|
|
19
|
+
// source: `<script src="pgia/index.js"></script>`,
|
|
20
|
+
source: `<script>/* Pinegrow Interactions, do not remove */ (function(){try{if(!document.documentElement.hasAttribute('data-pg-ia-disabled')) { window.pgia_small_mq=typeof pgia_small_mq=='string'?pgia_small_mq:'(max-width:767px)';window.pgia_large_mq=typeof pgia_large_mq=='string'?pgia_large_mq:'(min-width:768px)';var style = document.createElement('style');var pgcss='html:not(.pg-ia-no-preview) [data-pg-ia-hide=""] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show=""] {opacity:1;visibility:visible;display:block;}';if(document.documentElement.hasAttribute('data-pg-id') && document.documentElement.hasAttribute('data-pg-mobile')) {pgia_small_mq='(min-width:0)';pgia_large_mq='(min-width:99999px)'} pgcss+='@media ' + pgia_small_mq + '{ html:not(.pg-ia-no-preview) [data-pg-ia-hide="mobile"] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show="mobile"] {opacity:1;visibility:visible;display:block;}}';pgcss+='@media ' + pgia_large_mq + '{html:not(.pg-ia-no-preview) [data-pg-ia-hide="desktop"] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show="desktop"] {opacity:1;visibility:visible;display:block;}}';style.innerHTML=pgcss;document.querySelector('head').appendChild(style);}}catch(e){console&&console.log(e);}})()</script>`,
|
|
21
|
+
operation: 'append',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
parent: 'body',
|
|
25
|
+
parentResource: `public/pgia`, // relative to project root, must exists
|
|
26
|
+
source: `<script src="/pgia/lib/index.js"></script>`,
|
|
27
|
+
operation: 'append',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
addons.forEach(addon => {
|
|
34
|
+
addon.resources.forEach(resource => {
|
|
35
|
+
try {
|
|
36
|
+
let parentResourceExists = true
|
|
37
|
+
|
|
38
|
+
if (resource.parentResource) {
|
|
39
|
+
const projectRoot = process.cwd()
|
|
40
|
+
const resourcePath = path.resolve(
|
|
41
|
+
projectRoot,
|
|
42
|
+
resource.parentResource
|
|
43
|
+
)
|
|
44
|
+
parentResourceExists =
|
|
45
|
+
parentResourceExists && fs.existsSync(resourcePath)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (parentResourceExists) {
|
|
49
|
+
switch (resource.operation) {
|
|
50
|
+
case 'prepend':
|
|
51
|
+
switch (resource.parent) {
|
|
52
|
+
case 'head':
|
|
53
|
+
html.head.push(resource.source)
|
|
54
|
+
break
|
|
55
|
+
case 'body':
|
|
56
|
+
html.bodyPrepend.push(resource.source)
|
|
57
|
+
break
|
|
58
|
+
}
|
|
59
|
+
break
|
|
60
|
+
case 'append':
|
|
61
|
+
switch (resource.parent) {
|
|
62
|
+
case 'head':
|
|
63
|
+
html.head.push(resource.source)
|
|
64
|
+
break
|
|
65
|
+
case 'body':
|
|
66
|
+
html.bodyAppend.push(resource.source)
|
|
67
|
+
break
|
|
68
|
+
}
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
// console.log(err)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
// nitroApp.hooks.hook('render:response', (response, { event }) => {
|
|
79
|
+
// console.log('render:response', response)
|
|
80
|
+
// })
|
|
81
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinegrow/nuxt-module",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.80",
|
|
4
4
|
"description": "Pinegrow Nuxt Module",
|
|
5
5
|
"author": "Pinegrow (http://pinegrow.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@nuxt/kit": "latest",
|
|
38
|
-
"@pinegrow/vite-plugin": "3.0.0-beta.
|
|
38
|
+
"@pinegrow/vite-plugin": "3.0.0-beta.80"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@nuxt/module-builder": "latest",
|