Skip to content

Commit

Permalink
simplify bundlesize configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini committed Feb 26, 2024
1 parent 686c95b commit 0574068
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 117 deletions.
4 changes: 2 additions & 2 deletions packages/bundlesize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"private": true,
"scripts": {
"clean": "rimraf dist",
"build:components": "vite build -c vite.components.config.js",
"build:system": "vite build -c vite.system.config.js",
"build:components": "cross-env-shell VITE_UI_TARGET=components vite build",
"build:system": "cross-env-shell VITE_UI_TARGET=system vite build",
"build": "npm-run-all --serial clean build:components build:system",
"test": "echo \"WARNING: no test specified\" && exit 0",
"test:coverage": "echo \"WARNING: no test specified\" && exit 0"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/bundlesize/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["ui-components/src", "ui-system/src"],
"include": ["./src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
57 changes: 0 additions & 57 deletions packages/bundlesize/vite.components.config.ts

This file was deleted.

63 changes: 63 additions & 0 deletions packages/bundlesize/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/** @type {import('vite').UserConfig} */

import { resolve } from "node:path";

import fs from "fs-extra";
import { defineConfig, loadEnv } from "vite";

const VENDOR_CHUNK = "vendorChunk";

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const packageJson = fs.readJSONSync(
`../ui-${env.VITE_UI_TARGET}/package.json`,
);
const prodDependencies = Object.keys(packageJson.dependencies).filter(
(dependency) =>
dependency !== "react" &&
dependency !== "react-dom" &&
dependency !== "react/jsx-runtime" &&
dependency !== "react-dom/server" &&
dependency !== "tailwindcss",
);
prodDependencies.push(
"react-dom",
"react-dom/server",
"react",
"react/jsx-runtime",
);

return {
esbuild: {
supported: {
"top-level-await": true, //browsers can handle top-level-await features
},
},
build: {
outDir: `dist/${env.VITE_UI_TARGET}`,
emptyOutDir: false,
rollupOptions: {
input: {
index: resolve(__dirname, "src", env.VITE_UI_TARGET, "index.html"),
},
output: {
assetFileNames: "assets/style[extname]",
entryFileNames: "assets/[name].js",
/**
* Manually creating chunks for prod dependencies.
*/
manualChunks: {
[VENDOR_CHUNK]: prodDependencies,
},
chunkFileNames(chunkInfo) {
if (chunkInfo.name.includes(VENDOR_CHUNK)) {
return "assets/vendor.js";
}
return "[name]-[hash].js";
},
},
},
},
plugins: [],
};
});
57 changes: 0 additions & 57 deletions packages/bundlesize/vite.system.config.ts

This file was deleted.

0 comments on commit 0574068

Please sign in to comment.