@skyvexsoftware/stratos-sdk 0.1.14 → 0.1.15
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,47 @@
|
|
|
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
|
+
// Prepend CSS injection code to the JS entry
|
|
34
|
+
const escaped = cssContent
|
|
35
|
+
.replace(/\\/g, "\\\\")
|
|
36
|
+
.replace(/`/g, "\\`")
|
|
37
|
+
.replace(/\$/g, "\\$");
|
|
38
|
+
const injection = `(function(){try{var s=document.createElement("style");s.textContent=\`${escaped}\`;document.head.appendChild(s)}catch(e){}})();\n`;
|
|
39
|
+
jsEntry.code = injection + jsEntry.code;
|
|
40
|
+
// Remove the separate CSS files
|
|
41
|
+
for (const name of cssAssets) {
|
|
42
|
+
delete bundle[name];
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# 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
|
],
|