At first we wanted to only support ESM. But as we want to share types and export design tokens from the react package to the outside world in order to allow local cunningham.ts files to import them, we are forced to also build the library for CJS too. Why? Because local cunningham.ts files are loaded as CJS, so they can only import CJS module. Why loading cunningham.ts as CJS? Because the tokens package's binary is built for CJS, then it's seamless to make it load CJS, where making it load ESM was buggy. And why not migrate the tokens package to ESM so? Because it implies to rewrite every imports with .js extensions, makes us loose the possibility to use __dirname kind of variables. And also Jest use for testing is not compliant at all when it comes to execute ESM code. Well, the ecosystem is not ready for that at the moment, sadly.
63 lines
1.3 KiB
TypeScript
63 lines
1.3 KiB
TypeScript
import { resolve } from "path";
|
|
import { defineConfig } from "vitest/config";
|
|
import react from "@vitejs/plugin-react";
|
|
import dts from "vite-plugin-dts";
|
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
build: {
|
|
emptyOutDir: true,
|
|
outDir: "dist",
|
|
sourcemap: true,
|
|
lib: {
|
|
entry: {
|
|
index: "./src/index.ts",
|
|
},
|
|
formats: ["es", "cjs"],
|
|
},
|
|
rollupOptions: {
|
|
external: ["react", "react-dom"],
|
|
output: {
|
|
globals: {
|
|
react: "React",
|
|
"react-dom": "ReactDOM",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
plugins: [
|
|
tsconfigPaths(),
|
|
dts({
|
|
rollupTypes: true,
|
|
beforeWriteFile: (filePath, content) => {
|
|
return {
|
|
filePath,
|
|
content: content.replace("../../locales", "./locales"),
|
|
};
|
|
},
|
|
}),
|
|
react(),
|
|
],
|
|
test: {
|
|
environment: "jsdom",
|
|
reporters: "verbose",
|
|
globals: true,
|
|
watchExclude: ["**/cunningham-tokens.js"],
|
|
coverage: {
|
|
all: true,
|
|
include: ["src/**/*.{ts,tsx}"],
|
|
exclude: ["**/*.stories.tsx", "**/*.spec.tsx"],
|
|
},
|
|
setupFiles: ["src/tests/Setup.ts"],
|
|
},
|
|
resolve: {
|
|
alias: [
|
|
{
|
|
find: ":",
|
|
replacement: resolve(__dirname, "./src"),
|
|
},
|
|
],
|
|
},
|
|
});
|