Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"type": "module",
"dependencies": {
"@intechstudio/grid-protocol": "1.20260828.1315",
"@intechstudio/grid-uikit": "1.20261014.1208",
"@intechstudio/grid-uikit": "1.20261014.1352",
"@melt-ui/svelte": "^0.86.6",
"firebase": "^12.2.1",
"marked": "^12.0.2",
Expand Down
43 changes: 1 addition & 42 deletions vite.config.webcomponent.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
import { defineConfig, type Plugin } from "vite";
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { sveltePreprocess } from "svelte-preprocess";
import { notifyEditorAfterBuildPlugin } from "./vite.postbuild";
import path from "path";
import { existsSync, readFileSync, writeFileSync } from "fs";

// The host editor only loads components.js, so any CSS vite extracts into a
// separate file (e.g. grid-uikit's splitpanes theme) never reaches the page.
// Vite attaches the extracted CSS to a different output format depending on
// the mode (build vs --watch), so inject it into every entry file after all
// formats are written instead of per bundle.
function injectCssIntoJsPlugin(): Plugin {
const marker = "/*inject-css-into-js*/";
let outDir = "";
let css = "";
const entryFiles = new Set<string>();
return {
name: "inject-css-into-js",
apply: "build",
enforce: "post",
configResolved(config) {
outDir = path.resolve(config.root, config.build.outDir);
},
generateBundle(_, bundle) {
for (const [name, file] of Object.entries(bundle)) {
if (file.type === "chunk" && file.isEntry) entryFiles.add(name);
if (file.type === "asset" && name.endsWith(".css")) {
css = String(file.source);
delete bundle[name];
}
}
},
closeBundle() {
if (!css) return;
const snippet = `\n${marker};(function(){try{var s=document.createElement("style");s.textContent=${JSON.stringify(css)};document.head.appendChild(s);}catch(e){}})();`;
for (const name of entryFiles) {
const file = path.join(outDir, name);
if (!existsSync(file)) continue;
const code = readFileSync(file, "utf8");
if (!code.includes(marker)) writeFileSync(file, code + snippet);
}
},
};
}

export default defineConfig({
resolve: {
Expand Down Expand Up @@ -86,7 +46,6 @@ export default defineConfig({
},
emitCss: false,
}),
injectCssIntoJsPlugin(),
notifyEditorAfterBuildPlugin(),
],
build: {
Expand Down
Loading