diff --git a/packages/react/package.json b/packages/react/package.json index 2d4a9e7..2f7951e 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -26,8 +26,10 @@ ], "scripts": { "lint": "eslint . 'src/**/*.{ts,tsx}'", - "dev": "yarn storybook & nodemon --watch src --ext '*' --ignore src/cunningham-tokens.ts --ignore src/cunningham-tokens.js --ignore src/cunningham-tokens.css --exec npm run build", + "dev": "yarn storybook", "build": "bash ./build", + "build:watch": "yarn build && vite build --mode watch", + "build:watch-polling": "yarn build && vite build --mode watch-polling", "build-fonts": "vite build -c vite.fonts.config.ts && rm -rf dist/fonts.js && make-dir dist/sass && cp src/fonts.scss dist/sass/", "build-icons": "vite build -c vite.icons.config.ts && rm -rf dist/icons.js && make-dir dist/sass && cp src/icons.scss dist/sass/", "build-theme": "cunningham -o src -g css,ts,js", diff --git a/packages/react/vite.config.ts b/packages/react/vite.config.ts index 21a1c2b..5df1d50 100644 --- a/packages/react/vite.config.ts +++ b/packages/react/vite.config.ts @@ -3,61 +3,88 @@ import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; import dts from "vite-plugin-dts"; import tsconfigPaths from "vite-tsconfig-paths"; +import { BuildOptions } from "vite"; // https://vitejs.dev/config/ -export default defineConfig({ - build: { - emptyOutDir: true, - outDir: "dist", - sourcemap: true, - lib: { - entry: { - index: "./src/index.ts", +export default defineConfig(({ mode }) => { + let buildOptions: { watch: BuildOptions["watch"] }; + let emptyOutDir = true; + if (mode.includes("watch")) { + emptyOutDir = false; + buildOptions = { + watch: { + include: ["src/**/*"], }, - formats: ["es", "cjs"], - }, - rollupOptions: { - external: ["react", "react-dom"], - output: { - globals: { - react: "React", - "react-dom": "ReactDOM", + }; + + if (mode.includes("polling")) { + buildOptions = { + watch: { + ...buildOptions.watch, + chokidar: { + usePolling: true, + interval: 1000, + }, + }, + }; + } + } + + return { + build: { + emptyOutDir, + 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", + }, }, }, + ...buildOptions, }, - }, - 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"], - }, - globalSetup: ["src/tests/Global.ts"], - setupFiles: ["src/tests/Setup.ts"], - }, - resolve: { - alias: [ - { - find: ":", - replacement: resolve(__dirname, "./src"), - }, + 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"], + }, + globalSetup: ["src/tests/Global.ts"], + setupFiles: ["src/tests/Setup.ts"], + }, + resolve: { + alias: [ + { + find: ":", + replacement: resolve(__dirname, "./src"), + }, + ], + }, + }; });