Skip to content

Commit

Permalink
build: 🏗️ update vite config to new build/publish flow
Browse files Browse the repository at this point in the history
this changes should fix the problem on build time. The problem was mention by @rafalfigura in QwikDev/qwik#5473
  • Loading branch information
diecodev committed May 8, 2024
1 parent d892ed0 commit 50ddfaf
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ const makeRegex = (dep) => new RegExp(`^${dep}(/.*)?$`);
const excludeAll = (obj) => Object.keys(obj).map(makeRegex);

export default defineConfig(() => {
const env = process.env.ENTRY as "styled" | "headless" | undefined;

if (!env) throw new Error("ENTRY env var is required");

const entry =
env === "headless" ? "src/lib/headless/toast-wrapper.tsx" : "src/lib";

return {
build: {
target: "es2020",
outDir: "lib",
lib: {
entry: {
index: "./src/lib/",
headless: "./src/lib/headless",
core: "./src/lib/core",
},
entry,
formats: ["es", "cjs"],
fileName: (format, file) => {
const ext = format === "es" ? "mjs" : "cjs";
return `${file}.qwik.${ext}`;
const name = env === "styled" ? "index" : "headless";
return `${name}.qwik.${ext}`;
},
name: "qwik-toast",
},
emptyOutDir: true,
emptyOutDir: env === "styled" ? true : false,
rollupOptions: {
// externalize deps that shouldn't be bundled into the library
external: [
Expand All @@ -35,7 +38,7 @@ export default defineConfig(() => {
],
// all the chunks created by vite shuold also have qwik in the name
output: {
chunkFileNames: "[name]-[hash].qwik.js",
chunkFileNames: "[name]-[format].qwik.js",
},
},
},
Expand Down

0 comments on commit 50ddfaf

Please sign in to comment.