vite-plugin-garfish-mf 1.0.1 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ let _swc_core = require("@swc/core");
1
2
  let cheerio = require("cheerio");
2
3
 
3
4
  //#region src/utils.ts
@@ -40,45 +41,68 @@ function injectGarfishProvider(script$, publicPath) {
40
41
 
41
42
  //#endregion
42
43
  //#region src/plugin.ts
43
- const vitePluginGarfish = ({ base = "http://localhost:5173", sandbox = true }) => {
44
+ const vitePluginGarfish = ({ base = "http://localhost:5173", sandbox = true, esModule = false }) => {
44
45
  let config;
45
46
  let isUseWithReact;
46
- return [{
47
- name: "vite-plugin-garfish-fm:resolve-config",
48
- enforce: "post",
49
- config() {
50
- let url = new URL(base);
51
- return {
52
- base,
53
- server: {
54
- port: Number(url.port),
55
- origin: url.origin
56
- },
57
- preview: { port: Number(url.port) }
58
- };
47
+ return [
48
+ {
49
+ name: "vite-plugin-garfish-fm:resolve-config",
50
+ enforce: "post",
51
+ config() {
52
+ let url = new URL(base);
53
+ return {
54
+ base,
55
+ server: {
56
+ port: Number(url.port),
57
+ origin: url.origin
58
+ },
59
+ preview: { port: Number(url.port) }
60
+ };
61
+ },
62
+ configResolved(resolvedConfig) {
63
+ config = resolvedConfig;
64
+ isUseWithReact = config.plugins.findIndex((plugin) => plugin.name === "vite:react-swc" || plugin.name === "vite:react-babel") !== -1;
65
+ }
59
66
  },
60
- configResolved(resolvedConfig) {
61
- config = resolvedConfig;
62
- isUseWithReact = config.plugins.findIndex((plugin) => plugin.name === "vite:react-swc" || plugin.name === "vite:react-babel") !== -1;
63
- }
64
- }, {
65
- name: "vite-plugin-garfish-fm:html-transfrom",
66
- enforce: "post",
67
- apply: "serve",
68
- transformIndexHtml(html) {
69
- const $ = (0, cheerio.load)(html);
70
- const moduleScripts$ = $("body script[src][type], head script[src]");
71
- if (sandbox) injectGarfishProvider(moduleScripts$.last(), base);
72
- moduleScripts$.each((_, script$) => void scriptTransform($(script$), base));
73
- if (isUseWithReact) {
74
- const reactHMRScript = $("script:not([src])[type=module]").filter((_, el) => {
75
- return ($(el).html() || "").includes("/@react-refresh");
67
+ {
68
+ name: "vite-plugin-garfish-fm:html-transfrom",
69
+ enforce: "post",
70
+ apply: "serve",
71
+ transformIndexHtml(html) {
72
+ const $ = (0, cheerio.load)(html);
73
+ const moduleScripts$ = $("body script[src][type], head script[src]");
74
+ if (sandbox && !esModule) injectGarfishProvider(moduleScripts$.last(), base);
75
+ moduleScripts$.each((_, script$) => void scriptTransform($(script$), base));
76
+ if (isUseWithReact) {
77
+ const reactHMRScript = $("script:not([src])[type=module]").filter((_, el) => {
78
+ return ($(el).html() || "").includes("/@react-refresh");
79
+ });
80
+ if (reactHMRScript.length > 0) reactHRMScriptTransfrom($(reactHMRScript[0]), base);
81
+ }
82
+ return $.html();
83
+ }
84
+ },
85
+ {
86
+ name: "vite-plugin-garfish-fm:legacy-transform",
87
+ enforce: "post",
88
+ apply: "serve",
89
+ async transform(code) {
90
+ if (esModule) return null;
91
+ const result = await (0, _swc_core.transform)(code, {
92
+ jsc: {
93
+ target: "es2018",
94
+ parser: { syntax: "ecmascript" }
95
+ },
96
+ module: { type: "es6" },
97
+ sourceMaps: true
76
98
  });
77
- if (reactHMRScript.length > 0) reactHRMScriptTransfrom($(reactHMRScript[0]), base);
99
+ return {
100
+ code: result.code,
101
+ map: result.map
102
+ };
78
103
  }
79
- return $.html();
80
104
  }
81
- }];
105
+ ];
82
106
  };
83
107
 
84
108
  //#endregion
package/dist/index.d.cts CHANGED
@@ -1,13 +1,30 @@
1
- import { PluginOption } from "vite";
1
+ import { Plugin } from "vite";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  type Options = {
5
+ /**
6
+ * Set the base URL when serving dev server and base assets when building
7
+ *
8
+ * More info https://vite.dev/config/shared-options#base
9
+ */
5
10
  base: string;
11
+ /**
12
+ * Set to `true` if you are running sub-app in sandbox environment
13
+ *
14
+ * Read more: https://www.garfishjs.org/api/run.html#sandbox
15
+ *
16
+ */
6
17
  sandbox?: boolean;
18
+ /**
19
+ * Set to `true` if you are using plugin [GarfishEsModule](https://www.npmjs.com/package/@garfish/es-module)
20
+ *
21
+ */
22
+ esModule?: boolean;
7
23
  };
8
24
  declare const vitePluginGarfish: ({
9
25
  base,
10
- sandbox
11
- }: Options) => PluginOption;
26
+ sandbox,
27
+ esModule
28
+ }: Options) => Plugin[];
12
29
  //#endregion
13
30
  export { type Options, vitePluginGarfish as default };
package/dist/index.d.mts CHANGED
@@ -1,13 +1,30 @@
1
- import { PluginOption } from "vite";
1
+ import { Plugin } from "vite";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  type Options = {
5
+ /**
6
+ * Set the base URL when serving dev server and base assets when building
7
+ *
8
+ * More info https://vite.dev/config/shared-options#base
9
+ */
5
10
  base: string;
11
+ /**
12
+ * Set to `true` if you are running sub-app in sandbox environment
13
+ *
14
+ * Read more: https://www.garfishjs.org/api/run.html#sandbox
15
+ *
16
+ */
6
17
  sandbox?: boolean;
18
+ /**
19
+ * Set to `true` if you are using plugin [GarfishEsModule](https://www.npmjs.com/package/@garfish/es-module)
20
+ *
21
+ */
22
+ esModule?: boolean;
7
23
  };
8
24
  declare const vitePluginGarfish: ({
9
25
  base,
10
- sandbox
11
- }: Options) => PluginOption;
26
+ sandbox,
27
+ esModule
28
+ }: Options) => Plugin[];
12
29
  //#endregion
13
30
  export { type Options, vitePluginGarfish as default };
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { transform } from "@swc/core";
1
2
  import { load } from "cheerio";
2
3
 
3
4
  //#region src/utils.ts
@@ -40,45 +41,68 @@ function injectGarfishProvider(script$, publicPath) {
40
41
 
41
42
  //#endregion
42
43
  //#region src/plugin.ts
43
- const vitePluginGarfish = ({ base = "http://localhost:5173", sandbox = true }) => {
44
+ const vitePluginGarfish = ({ base = "http://localhost:5173", sandbox = true, esModule = false }) => {
44
45
  let config;
45
46
  let isUseWithReact;
46
- return [{
47
- name: "vite-plugin-garfish-fm:resolve-config",
48
- enforce: "post",
49
- config() {
50
- let url = new URL(base);
51
- return {
52
- base,
53
- server: {
54
- port: Number(url.port),
55
- origin: url.origin
56
- },
57
- preview: { port: Number(url.port) }
58
- };
47
+ return [
48
+ {
49
+ name: "vite-plugin-garfish-fm:resolve-config",
50
+ enforce: "post",
51
+ config() {
52
+ let url = new URL(base);
53
+ return {
54
+ base,
55
+ server: {
56
+ port: Number(url.port),
57
+ origin: url.origin
58
+ },
59
+ preview: { port: Number(url.port) }
60
+ };
61
+ },
62
+ configResolved(resolvedConfig) {
63
+ config = resolvedConfig;
64
+ isUseWithReact = config.plugins.findIndex((plugin) => plugin.name === "vite:react-swc" || plugin.name === "vite:react-babel") !== -1;
65
+ }
59
66
  },
60
- configResolved(resolvedConfig) {
61
- config = resolvedConfig;
62
- isUseWithReact = config.plugins.findIndex((plugin) => plugin.name === "vite:react-swc" || plugin.name === "vite:react-babel") !== -1;
63
- }
64
- }, {
65
- name: "vite-plugin-garfish-fm:html-transfrom",
66
- enforce: "post",
67
- apply: "serve",
68
- transformIndexHtml(html) {
69
- const $ = load(html);
70
- const moduleScripts$ = $("body script[src][type], head script[src]");
71
- if (sandbox) injectGarfishProvider(moduleScripts$.last(), base);
72
- moduleScripts$.each((_, script$) => void scriptTransform($(script$), base));
73
- if (isUseWithReact) {
74
- const reactHMRScript = $("script:not([src])[type=module]").filter((_, el) => {
75
- return ($(el).html() || "").includes("/@react-refresh");
67
+ {
68
+ name: "vite-plugin-garfish-fm:html-transfrom",
69
+ enforce: "post",
70
+ apply: "serve",
71
+ transformIndexHtml(html) {
72
+ const $ = load(html);
73
+ const moduleScripts$ = $("body script[src][type], head script[src]");
74
+ if (sandbox && !esModule) injectGarfishProvider(moduleScripts$.last(), base);
75
+ moduleScripts$.each((_, script$) => void scriptTransform($(script$), base));
76
+ if (isUseWithReact) {
77
+ const reactHMRScript = $("script:not([src])[type=module]").filter((_, el) => {
78
+ return ($(el).html() || "").includes("/@react-refresh");
79
+ });
80
+ if (reactHMRScript.length > 0) reactHRMScriptTransfrom($(reactHMRScript[0]), base);
81
+ }
82
+ return $.html();
83
+ }
84
+ },
85
+ {
86
+ name: "vite-plugin-garfish-fm:legacy-transform",
87
+ enforce: "post",
88
+ apply: "serve",
89
+ async transform(code) {
90
+ if (esModule) return null;
91
+ const result = await transform(code, {
92
+ jsc: {
93
+ target: "es2018",
94
+ parser: { syntax: "ecmascript" }
95
+ },
96
+ module: { type: "es6" },
97
+ sourceMaps: true
76
98
  });
77
- if (reactHMRScript.length > 0) reactHRMScriptTransfrom($(reactHMRScript[0]), base);
99
+ return {
100
+ code: result.code,
101
+ map: result.map
102
+ };
78
103
  }
79
- return $.html();
80
104
  }
81
- }];
105
+ ];
82
106
  };
83
107
 
84
108
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-garfish-mf",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A vite plugin for running Micro frontend applications using garfish",
5
5
  "keywords": [
6
6
  "@garfish/react-bridge",
@@ -45,10 +45,11 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "cheerio": "^1.2.0"
48
+ "@swc/core": "^1.15.11",
49
+ "cheerio": "^1.2.0",
50
+ "domhandler": "^5.0.3"
49
51
  },
50
52
  "devDependencies": {
51
- "domhandler": "^5.0.3",
52
53
  "tsdown": "^0.20.3"
53
54
  },
54
55
  "peerDependencies": {