@hitachivantara/app-shell-vite-plugin 1.10.0 → 1.10.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.
|
@@ -8,9 +8,8 @@ export declare const getExtraDependenciesString: () => string;
|
|
|
8
8
|
/**
|
|
9
9
|
* Generate and injects the importmap tag into index.html
|
|
10
10
|
* @param importmapElements The importmap elements to be included
|
|
11
|
-
* @param packageName The application name identifier
|
|
12
11
|
* @param sharedDependencies The shared packages (other than application bundles)
|
|
13
12
|
* @param externalImportMap Flag to control if the importmap should be externalized
|
|
14
13
|
* @param placeholderEntryPoint Flag to control if the importmap should be a placeholder
|
|
15
14
|
*/
|
|
16
|
-
export default function generateImportmap(importmapElements: Record<string, string>,
|
|
15
|
+
export default function generateImportmap(importmapElements: Record<string, string>, sharedDependencies: string[], externalImportMap?: boolean, placeholderEntryPoint?: boolean): PluginOption;
|
|
@@ -18,15 +18,12 @@ export const getExtraDependenciesString = () => {
|
|
|
18
18
|
extraDependenciesString = extraDependenciesString.slice(0, -1);
|
|
19
19
|
return extraDependenciesString;
|
|
20
20
|
};
|
|
21
|
-
function
|
|
22
|
-
const reg = new RegExp(`(/${packageName})?${ID_PREFIX}(${keys.join("|")})`, "g");
|
|
21
|
+
function markExternal(keys) {
|
|
23
22
|
return {
|
|
24
|
-
name: "vite-plugin-importmap-
|
|
23
|
+
name: "vite-plugin-importmap-mark-external",
|
|
25
24
|
enforce: "pre",
|
|
26
25
|
apply: "serve",
|
|
27
|
-
// while in dev, we need to
|
|
28
|
-
transform: (code) => reg.test(code) ? code.replace(reg, (m, s1, s2) => s2) : code,
|
|
29
|
-
// and to say its resolved (as external)
|
|
26
|
+
// while in dev, we need to mark keys from the importmapElements that match the id as external)
|
|
30
27
|
resolveId: (id) => keys.some((key) => typeof key === "string" ? id.startsWith(key) : key.test(id))
|
|
31
28
|
? {
|
|
32
29
|
id,
|
|
@@ -44,15 +41,24 @@ function replaceIdPrefix(keys, packageName) {
|
|
|
44
41
|
},
|
|
45
42
|
};
|
|
46
43
|
}
|
|
44
|
+
function replaceIdPrefix(keys) {
|
|
45
|
+
const reg = new RegExp(`${ID_PREFIX}(${keys.join("|")})`, "g");
|
|
46
|
+
return {
|
|
47
|
+
name: "vite-plugin-importmap-replace-idprefix",
|
|
48
|
+
enforce: "pre",
|
|
49
|
+
apply: "serve",
|
|
50
|
+
// while in dev, we need to prevent 'vite:import-analysis' on runtime modules
|
|
51
|
+
transform: (code) => reg.test(code) ? code.replace(reg, (m, s1) => s1) : code,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
47
54
|
/**
|
|
48
55
|
* Generate and injects the importmap tag into index.html
|
|
49
56
|
* @param importmapElements The importmap elements to be included
|
|
50
|
-
* @param packageName The application name identifier
|
|
51
57
|
* @param sharedDependencies The shared packages (other than application bundles)
|
|
52
58
|
* @param externalImportMap Flag to control if the importmap should be externalized
|
|
53
59
|
* @param placeholderEntryPoint Flag to control if the importmap should be a placeholder
|
|
54
60
|
*/
|
|
55
|
-
export default function generateImportmap(importmapElements,
|
|
61
|
+
export default function generateImportmap(importmapElements, sharedDependencies, externalImportMap = false, placeholderEntryPoint = false) {
|
|
56
62
|
const keys = Object.keys(importmapElements);
|
|
57
63
|
const devKeys = keys.filter((key) => !sharedDependencies.some((lib) => lib.startsWith(key)));
|
|
58
64
|
let devMode = false;
|
|
@@ -127,8 +133,23 @@ document.currentScript.after(im);
|
|
|
127
133
|
if (!devMode) {
|
|
128
134
|
return;
|
|
129
135
|
}
|
|
130
|
-
//
|
|
131
|
-
|
|
136
|
+
// this is a hack: we want to add the plugins only after the config is resolved,
|
|
137
|
+
// however, because vite:react-refresh overrides the `resolveId` hook,
|
|
138
|
+
// we need to add our `markExternal` before it
|
|
139
|
+
const index = resolvedConfig.plugins.findIndex((plugin) => plugin.name === "vite:react-refresh");
|
|
140
|
+
// if the plugin changes its name or is removed, fallback to as it was
|
|
141
|
+
if (index === -1) {
|
|
142
|
+
// @ts-expect-error
|
|
143
|
+
resolvedConfig.plugins.push(markExternal(devKeys));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// if present, `markExternal` will be put right before the `vite:react-refresh` plugin
|
|
147
|
+
// @ts-expect-error
|
|
148
|
+
resolvedConfig.plugins.splice(index, 0, markExternal(devKeys));
|
|
149
|
+
}
|
|
150
|
+
// `replaceIdPrefix` transformation can be put at the end as it was
|
|
151
|
+
// @ts-expect-error
|
|
152
|
+
resolvedConfig.plugins.push(replaceIdPrefix(devKeys));
|
|
132
153
|
},
|
|
133
154
|
/**
|
|
134
155
|
* Rollup hook with the info for bundle generation
|
package/dist/vite-plugin.js
CHANGED
|
@@ -102,7 +102,7 @@ export function HvAppShellVitePlugin(opts = {}, env = {}) {
|
|
|
102
102
|
return acc;
|
|
103
103
|
}, {})
|
|
104
104
|
: {}),
|
|
105
|
-
},
|
|
105
|
+
}, [...SHARED_DEPENDENCIES.map((dep) => dep.moduleId), packageJson.name], externalImportMap && buildEntryPoint, generateEmptyShell),
|
|
106
106
|
// inject version metadata in the index.html
|
|
107
107
|
buildEntryPoint && injectMetadata(),
|
|
108
108
|
// set the base tag and replace the title in the index.html
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/app-shell-vite-plugin",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Hitachi Vantara UI Kit Team",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"@emotion/cache": "^11.11.0",
|
|
22
22
|
"@emotion/react": "^11.11.1",
|
|
23
23
|
"@hitachivantara/app-shell-services": "^1.1.2",
|
|
24
|
-
"@hitachivantara/app-shell-shared": "^1.7.
|
|
25
|
-
"@hitachivantara/app-shell-ui": "^1.13.
|
|
26
|
-
"@hitachivantara/uikit-react-icons": "^5.16.
|
|
27
|
-
"@hitachivantara/uikit-react-shared": "^5.5.
|
|
24
|
+
"@hitachivantara/app-shell-shared": "^1.7.6",
|
|
25
|
+
"@hitachivantara/app-shell-ui": "^1.13.6",
|
|
26
|
+
"@hitachivantara/uikit-react-icons": "^5.16.6",
|
|
27
|
+
"@hitachivantara/uikit-react-shared": "^5.5.6",
|
|
28
28
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
29
29
|
"@rollup/plugin-json": "^6.0.0",
|
|
30
30
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
},
|
|
60
60
|
"./package.json": "./package.json"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "7d60bff02f58ff47ae19146532553882c2e4b732"
|
|
63
63
|
}
|