Skip to content
Snippets Groups Projects
Commit 1f590f58 authored by Midhun Suresh's avatar Midhun Suresh
Browse files

Fix build

parent 88b294ae
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"scripts": { "scripts": {
"start": "vite", "start": "vite",
"build": "tsc && vite build", "build": "tsc && vite build && vite build --config parent-vite.config.js",
"preview": "vite preview" "preview": "vite preview"
}, },
"devDependencies": { "devDependencies": {
......
const { defineConfig } = require("vite")
const { resolve } = require("path");
import manifestJSON from "./target/manifest.json";
const cssLink = manifestJSON["index.html"]["css"][0];
module.exports = defineConfig({
build: {
rollupOptions: {
input: {
parent: resolve(__dirname, "index.html"),
},
},
outDir: "./target/parent",
target: 'esnext',
assetsInlineLimit: 0,
},
define: {
cssFileName: cssLink.replace(/assets\//, ""),
}
});
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
width: 0; width: 0;
} }
@media (max-width: 800px) { @media (max-width: 800px) {
.chatterbox-iframe { .chatterbox-iframe {
bottom: 0; bottom: 0;
right: 0; right: 0;
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
width: 32px; width: 32px;
height: 32px; height: 32px;
border: none; border: none;
background: no-repeat center #295dbd; background: no-repeat center url('./ui/res/chat-bubbles.svg'), #295dbd;
border-radius: 2px; border-radius: 2px;
cursor: pointer; cursor: pointer;
} }
......
import startButtonIcon from "./ui/res/chat-bubbles.svg"; import "./parent-style.css";
let isIframeLoaded = false; let isIframeLoaded = false;
const rootHost = (document.querySelector("#chatterbox-script") as HTMLScriptElement).src; const parentRootHost = (document.querySelector("#chatterbox-script") as HTMLScriptElement).src;
const parentRootHostURL = new URL(parentRootHost);
const rootHost = `${parentRootHostURL.protocol}${parentRootHostURL.host}`;
const sizeCollection = { const sizeCollection = {
"desktop": { "desktop": {
...@@ -37,8 +39,6 @@ function renderStartButton() { ...@@ -37,8 +39,6 @@ function renderStartButton() {
const button = document.createElement("button"); const button = document.createElement("button");
button.className = "StartChat"; button.className = "StartChat";
button.onclick = () => isIframeLoaded? minimizeIframe() : loadChatterboxIframe(); button.onclick = () => isIframeLoaded? minimizeIframe() : loadChatterboxIframe();
const fixedStartButtonIcon = new URL(startButtonIcon, rootHost).href;
button.style.backgroundImage = `url(${fixedStartButtonIcon})`;
container.appendChild(button); container.appendChild(button);
document.body.appendChild(container); document.body.appendChild(container);
} }
...@@ -46,8 +46,7 @@ function renderStartButton() { ...@@ -46,8 +46,7 @@ function renderStartButton() {
function loadCSS() { function loadCSS() {
const linkElement = document.createElement("link") as HTMLLinkElement; const linkElement = document.createElement("link") as HTMLLinkElement;
linkElement.rel = "stylesheet"; linkElement.rel = "stylesheet";
const url = new URL("./parent-style.css", import.meta.url); const urlFixed = new URL("cssFileName", parentRootHost);
const urlFixed = new URL(url.pathname, rootHost);
linkElement.href = urlFixed.href; linkElement.href = urlFixed.href;
document.head.appendChild(linkElement); document.head.appendChild(linkElement);
} }
...@@ -58,7 +57,7 @@ function loadChatterboxIframe() { ...@@ -58,7 +57,7 @@ function loadChatterboxIframe() {
if (!configLocation) { if (!configLocation) {
throw new Error("CONFIG_LOCATION is not set"); throw new Error("CONFIG_LOCATION is not set");
} }
iframe.src = new URL("../chatterbox.html?config=" + configLocation, import.meta.url).href; iframe.src = new URL("../chatterbox.html?config=" + configLocation, rootHost).href;
iframe.className = "chatterbox-iframe"; iframe.className = "chatterbox-iframe";
document.body.appendChild(iframe); document.body.appendChild(iframe);
isIframeLoaded = true; isIframeLoaded = true;
......
const { defineConfig } = require("vite") const { defineConfig } = require("vite");
const { resolve } = require("path"); const { resolve } = require("path");
module.exports = defineConfig({ module.exports = defineConfig(({ command }) => {
build: { if (command === "serve") {
rollupOptions: { return {
input: { // dev specific config
main: resolve(__dirname, "chatterbox.html"), define: {
parent: resolve(__dirname, "index.html"), cssFileName: JSON.stringify("parent-style.css"),
}, },
}, };
outDir: "./target", } else {
target: 'esnext', return {
assetsInlineLimit: 0, // build specific config
build: {
rollupOptions: {
input: {
main: resolve(__dirname, "chatterbox.html"),
parent: resolve(__dirname, "index.html"),
},
},
outDir: "./target",
target: "esnext",
assetsInlineLimit: 0,
manifest: true,
},
};
} }
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment