From 9dd692cbf27c9e92545d31ae841afd1139a14ba8 Mon Sep 17 00:00:00 2001 From: Torben Brenner Date: Mon, 28 Oct 2024 16:22:30 +0100 Subject: [PATCH 1/3] fix: ensure dist directories structure for watch --- vite.config.ts | 50 +++----------------------------------------------- 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index b8fd4374..cc75d417 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -13,7 +13,6 @@ export default defineConfig({ root: "./packages/lib/", build: { outDir: "../../dist", - emptyOutDir: true, lib: { entry: "./index.ts", // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -21,9 +20,9 @@ export default defineConfig({ name: pkg.name.replace(/-./g, (char) => char[1].toUpperCase()), fileName: (format) => ({ - es: `${pkg.name}.js`, - esm: `${pkg.name}.min.js`, - umd: `${pkg.name}.umd.js`, + es: `${pkg.name.replace("@samply/", "")}.js`, + esm: `${pkg.name.replace("@samply/", "")}.min.js`, + umd: `${pkg.name.replace("@samply/", "")}.umd.js`, })[format], }, rollupOptions: { @@ -45,7 +44,6 @@ export default defineConfig({ }), dts({ insertTypesEntry: true, - outDir: "../../dist", include: ["**/types/*.ts"], afterBuild: afterBuild, }), @@ -81,14 +79,6 @@ function minifyEs(): PluginOption { */ function afterBuild(): void { concatenateDeclarationFiles("./dist/src/types/"); - - /** - * Building somehow adds another @samply folder to the dist folder so this workaround is needed - * to move the files to the root of the dist folder and delete the unnecessary folder - */ - if (fs.existsSync("./dist/@samply/")) { - restructureDirectory("./dist/@samply/"); - } } /** @@ -107,40 +97,6 @@ function concatenateDeclarationFiles(folderPath: string): void { fs.rmSync("./dist/src", { recursive: true, force: true }); } -/** - * Restructure the directory to match the npm package structure - * this removes the @samply folder and moves the files to the root of the dist folder - * @param path the path where the files are located - */ -function restructureDirectory(path: string): void { - moveFile(`${path}lens.js`, "./dist/lens.js"); - moveFile(`${path}lens.min.js`, "./dist/lens.min.js"); - moveFile(`${path}lens.umd.js`, "./dist/lens.umd.js"); -} - -/** - * Moves a file from the oldFile to the target - * Removes the @samply folder if it is empty - * @param oldFile the path of the old file - * @param target the path of the target file - */ -function moveFile(oldFile: string, target: string): void { - let attempts = 0; - const interval = setInterval(() => { - attempts++; - if (fs.readFileSync(oldFile, "utf-8").length > 0) { - fs.renameSync(oldFile, target); - clearInterval(interval); - } else if (attempts > 10) { - clearInterval(interval); - throw new Error("File not found"); - } - if (fs.readdirSync("./dist/@samply/").length === 0) { - fs.rmSync("./dist/@samply/", { recursive: true, force: true }); - } - }, 1000); -} - /** * removes all import statements from a file * @param filePath the path of the file From 383ac917998f949a6e5bf6e6a79fa82430434385 Mon Sep 17 00:00:00 2001 From: Torben Brenner Date: Tue, 29 Oct 2024 15:17:39 +0100 Subject: [PATCH 2/3] fix: adjusted link and build script npm link should also work in the root of the repository --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e8897ab3..f0d9d1fa 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,13 @@ "scripts": { "start": "npm run dev -s", "dev": "vite --config vite.demo.config.ts", - "build": "vite build", + "build": "rimraf dist && vite build", "build:demo": "node options_tester.cjs && vite build --config vite.demo.config.ts", "preview": "vite preview --config vite.demo.config.ts", "check": "node options_tester.cjs && svelte-check --tsconfig ./tsconfig.json", "lint": "lint-staged", "watch": "rimraf dist && vite build --watch", - "link": "wait-on dist/types.d.ts && cd dist/ && npm link", + "link": "wait-on dist/types.d.ts && npm link", "prepublishOnly": "npm run build -s", "security:check": "npm audit --omit=dev --audit-level high", "prepare": "husky install", From d56cb7b8ae19ecafe6ce71a5714fcdd6396aa349 Mon Sep 17 00:00:00 2001 From: Torben Brenner Date: Wed, 30 Oct 2024 11:00:40 +0100 Subject: [PATCH 3/3] docs: added documentation for applications built with vite --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 4263d28c..4680c4c1 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,18 @@ If you want to make changes to the lens library while integrating those changes To controll that the linking of the local version worked, run `npm ls | grep lens` in your applications repository and verify that it refers to your local lens repository. +#### Additional Note for Applications using Vite +When your depending application is built with vite, you need to ensure to add the following to your vite.config.ts: + +``` javascript +export default defineConfig({ + // ... + optimizeDeps: { + exclude: ['@samply/lens'] + } +}); +``` + ## Style Integration To import the default stylings, use