@skyvexsoftware/stratos-sdk 0.1.14 → 0.1.16
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin that injects extracted CSS into the JS bundle for library mode.
|
|
3
|
+
*
|
|
4
|
+
* In Vite library mode, CSS imports are extracted to a separate .css file.
|
|
5
|
+
* Since plugins are loaded via dynamic import(), the CSS file is never loaded.
|
|
6
|
+
* This plugin moves the CSS content into the JS entry chunk so it's injected
|
|
7
|
+
* into the DOM automatically when the plugin module is imported.
|
|
8
|
+
*/
|
|
9
|
+
import type { Plugin } from "vite";
|
|
10
|
+
export declare function cssInject(): Plugin;
|
|
11
|
+
//# sourceMappingURL=css-inject.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin that injects extracted CSS into the JS bundle for library mode.
|
|
3
|
+
*
|
|
4
|
+
* In Vite library mode, CSS imports are extracted to a separate .css file.
|
|
5
|
+
* Since plugins are loaded via dynamic import(), the CSS file is never loaded.
|
|
6
|
+
* This plugin moves the CSS content into the JS entry chunk so it's injected
|
|
7
|
+
* into the DOM automatically when the plugin module is imported.
|
|
8
|
+
*/
|
|
9
|
+
export function cssInject() {
|
|
10
|
+
return {
|
|
11
|
+
name: "stratos-css-inject",
|
|
12
|
+
apply: "build",
|
|
13
|
+
enforce: "post",
|
|
14
|
+
generateBundle(_, bundle) {
|
|
15
|
+
// Find emitted CSS assets
|
|
16
|
+
const cssAssets = [];
|
|
17
|
+
let cssContent = "";
|
|
18
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
19
|
+
if (fileName.endsWith(".css") && chunk.type === "asset") {
|
|
20
|
+
cssContent +=
|
|
21
|
+
typeof chunk.source === "string"
|
|
22
|
+
? chunk.source
|
|
23
|
+
: new TextDecoder().decode(chunk.source);
|
|
24
|
+
cssAssets.push(fileName);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!cssContent)
|
|
28
|
+
return;
|
|
29
|
+
// Find the JS entry chunk
|
|
30
|
+
const jsEntry = Object.values(bundle).find((chunk) => chunk.type === "chunk" && chunk.isEntry);
|
|
31
|
+
if (!jsEntry || jsEntry.type !== "chunk")
|
|
32
|
+
return;
|
|
33
|
+
// Export the CSS as __STRATOS_PLUGIN_CSS__ so the shell's PluginHost
|
|
34
|
+
// can inject/remove it based on plugin lifecycle (mount/unmount).
|
|
35
|
+
//
|
|
36
|
+
// Also self-inject via IIFE for backwards compatibility with older shells
|
|
37
|
+
// that don't manage plugin CSS lifecycle. The IIFE tags its <style> with
|
|
38
|
+
// data-plugin-css-fallback so the new shell can remove it when it takes over.
|
|
39
|
+
const escaped = cssContent
|
|
40
|
+
.replace(/\\/g, "\\\\")
|
|
41
|
+
.replace(/`/g, "\\`")
|
|
42
|
+
.replace(/\$/g, "\\$");
|
|
43
|
+
const injection = [
|
|
44
|
+
`export const __STRATOS_PLUGIN_CSS__ = \`${escaped}\`;`,
|
|
45
|
+
`(function(){try{var s=document.createElement("style");s.textContent=\`${escaped}\`;s.setAttribute("data-plugin-css-fallback","");document.head.appendChild(s)}catch(e){}})();`,
|
|
46
|
+
"",
|
|
47
|
+
].join("\n");
|
|
48
|
+
jsEntry.code = injection + jsEntry.code;
|
|
49
|
+
// Remove the separate CSS files
|
|
50
|
+
for (const name of cssAssets) {
|
|
51
|
+
delete bundle[name];
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=css-inject.js.map
|
|
@@ -21,6 +21,7 @@ import MagicString from "magic-string";
|
|
|
21
21
|
import { UI_EXTERNALS } from "./externals.js";
|
|
22
22
|
import { serveExternals } from "./serve-externals.js";
|
|
23
23
|
import { stratosDevServer } from "./stratos-dev-server.js";
|
|
24
|
+
import { cssInject } from "./css-inject.js";
|
|
24
25
|
/** Modules external in background builds (available in Electron main process) */
|
|
25
26
|
const BG_EXTERNALS = ["electron", "socket.io-client"];
|
|
26
27
|
/** Node.js built-in modules to externalize in background builds */
|
|
@@ -241,6 +242,7 @@ function createUIConfig(pluginDir, entry, extraConfig) {
|
|
|
241
242
|
},
|
|
242
243
|
sourcemap: true,
|
|
243
244
|
minify: isProduction ? "esbuild" : false,
|
|
245
|
+
assetsInlineLimit: 10 * 1024 * 1024,
|
|
244
246
|
},
|
|
245
247
|
esbuild: {
|
|
246
248
|
jsx: "automatic",
|
|
@@ -252,6 +254,7 @@ function createUIConfig(pluginDir, entry, extraConfig) {
|
|
|
252
254
|
serveExternals(),
|
|
253
255
|
stratosDevServer({ pluginDir }),
|
|
254
256
|
stratosExternals(),
|
|
257
|
+
cssInject(),
|
|
255
258
|
copyPluginAssets(pluginDir),
|
|
256
259
|
...(extraConfig?.plugins ?? []),
|
|
257
260
|
],
|