@merkur/integration-custom-element 0.36.2 → 0.36.3

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.
File without changes
package/cli/index.mjs CHANGED
@@ -1,5 +1,72 @@
1
+ import fs from 'node:fs';
2
+
3
+ import { createLogger } from '@merkur/cli';
1
4
  import { createAssets } from '@merkur/integration/server';
2
5
 
6
+ export function merkurCustomElementCssBundlePlugin({ cliConfig, config }) {
7
+ const { projectFolder } = cliConfig;
8
+ const { writeToDisk } = config;
9
+ const logger = createLogger('merkurCustomElementCssBundlePlugin', cliConfig);
10
+
11
+ return {
12
+ name: 'merkurCustomElementCssBundlePlugin',
13
+ setup(build) {
14
+ build.onResolve(
15
+ { filter: /@merkur\/integration-custom-element\/cssBundle/ },
16
+ (args) => {
17
+ return {
18
+ path: args.path,
19
+ namespace: 'merkur-custom-element-css-bundle',
20
+ };
21
+ },
22
+ );
23
+
24
+ build.onLoad(
25
+ {
26
+ filter: /@merkur\/integration-custom-element\/cssBundle/,
27
+ namespace: 'merkur-custom-element-css-bundle',
28
+ },
29
+ async () => {
30
+ return {
31
+ contents: 'var STYLE={__bundle__:""}; export default STYLE;',
32
+ };
33
+ },
34
+ );
35
+
36
+ build.onEnd((result) => {
37
+ if (!writeToDisk) {
38
+ logger.debug('merkurCustomElementCssBundlePlugin is disabled');
39
+ }
40
+
41
+ Object.keys(result?.metafile?.outputs ?? {}).map((key) => {
42
+ const value = result.metafile.outputs[key];
43
+
44
+ if ('cssBundle' in value) {
45
+ try {
46
+ let css = fs.readFileSync(`${projectFolder}/${value.cssBundle}`, {
47
+ encoding: 'utf8',
48
+ flag: 'r',
49
+ });
50
+ css = css.replace(/\n/g, ' ');
51
+
52
+ let js = fs.readFileSync(`${projectFolder}/${key}`, {
53
+ encoding: 'utf8',
54
+ flag: 'r',
55
+ });
56
+ js = js.replace('{__bundle__:""}', `\`${css}\``);
57
+ js = js.replace('{ __bundle__: "" };', `\`${css}\``);
58
+
59
+ fs.writeFileSync(`${projectFolder}/${key}`, js);
60
+ } catch (error) {
61
+ logger.error(error);
62
+ }
63
+ }
64
+ });
65
+ });
66
+ },
67
+ };
68
+ }
69
+
3
70
  export default function ({ emitter, EMITTER_EVENTS }) {
4
71
  emitter.on(
5
72
  EMITTER_EVENTS.MERKUR_CONFIG,
@@ -14,10 +81,6 @@ export default function ({ emitter, EMITTER_EVENTS }) {
14
81
  name: 'widget.js',
15
82
  type: 'script',
16
83
  },
17
- {
18
- name: 'widget.css',
19
- type: 'stylesheet',
20
- },
21
84
  ],
22
85
  staticFolder,
23
86
  staticBaseUrl: `${protocol}//${host}${staticPath}`,
@@ -60,4 +123,23 @@ export default function ({ emitter, EMITTER_EVENTS }) {
60
123
  return cliConfig;
61
124
  },
62
125
  );
126
+
127
+ emitter.on(
128
+ EMITTER_EVENTS.CLI_CONFIG,
129
+ function forceWriteToDisk({ cliConfig }) {
130
+ cliConfig.writeToDisk = true;
131
+
132
+ return cliConfig;
133
+ },
134
+ );
135
+
136
+ emitter.on(
137
+ EMITTER_EVENTS.TASK_BUILD,
138
+ function registerCustomElementPlugin(event) {
139
+ const { build } = event;
140
+ build.plugins.push(merkurCustomElementCssBundlePlugin(event));
141
+
142
+ return build;
143
+ },
144
+ );
63
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkur/integration-custom-element",
3
- "version": "0.36.2",
3
+ "version": "0.36.3",
4
4
  "description": "Merkur module for easy integration with other apps with custom element.",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -8,6 +8,7 @@
8
8
  "sideEffects": false,
9
9
  "exports": {
10
10
  "./cli": "./cli/index.mjs",
11
+ "./cssBundle": "./cli/cssBundle.mjs",
11
12
  ".": {
12
13
  "import": "./lib/index.mjs",
13
14
  "require": "./lib/index.cjs"
@@ -57,5 +58,5 @@
57
58
  "@merkur/core": "*",
58
59
  "@merkur/integration": "*"
59
60
  },
60
- "gitHead": "e12bdfa8ff7e8f927edd757d051a90ddf9a95b01"
61
+ "gitHead": "bda01b8902e75089b69748bb98b8128b80ca0e87"
61
62
  }