From d8e133e3896df1de347db72fb6fa186762d873ae Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Mon, 17 Feb 2025 02:00:10 +0200 Subject: [PATCH] feat: use vite's build Signed-off-by: Ivaylo Nikolov --- Taskfile.yml | 1 + package.json | 3 ++- pnpm-lock.yaml | 9 +++++++++ vite.config.js | 39 ++++++++++++++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 2aa574440..ca3f99b32 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -72,6 +72,7 @@ tasks: - task: format - task: lint - npx babel src -d lib --out-file-extension .cjs > /dev/null + - npx vite build > /dev/null - npx yalc publish > /dev/null clean: diff --git a/package.json b/package.json index c1071eed4..a8bddb530 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "./package.json": "./package.json", ".": { "types": "./lib/index.d.ts", - "import": "./src/index.js", + "import": "./lib/index.js", "require": "./lib/index.cjs" } }, @@ -119,6 +119,7 @@ "typedoc": "^0.27.6", "typescript": "^5.7.2", "vite": "^6.1.0", + "vite-bundle-analyzer": "^0.17.0", "yalc": "1.0.0-pre.53" }, "peerDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c2113fc2..9bdcf0e98 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -204,6 +204,9 @@ importers: vite: specifier: ^6.1.0 version: 6.1.0(@types/node@22.12.0)(yaml@2.7.0) + vite-bundle-analyzer: + specifier: ^0.17.0 + version: 0.17.0 yalc: specifier: 1.0.0-pre.53 version: 1.0.0-pre.53 @@ -5073,6 +5076,10 @@ packages: validate-npm-package-name@3.0.0: resolution: {integrity: sha512-M6w37eVCMMouJ9V/sdPGnC5H4uDr73/+xdq0FBLO3TFFX1+7wiUY6Es328NN+y43tmY+doUdN9g9J21vqB7iLw==} + vite-bundle-analyzer@0.17.0: + resolution: {integrity: sha512-pSQng2NuhPo13hdSFcjW/Kjq8hmdfzCkJhWvAP5g98WbqZvy1k3Z+cpDxD9oxdNqOHHQFnEAIHR/MY6El1NnHA==} + hasBin: true + vite@6.1.0: resolution: {integrity: sha512-RjjMipCKVoR4hVfPY6GQTgveinjNuyLw+qruksLDvA5ktI1150VmcMBKmQaEWJhg/j6Uaf6dNCNA0AfdzUb/hQ==} engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} @@ -10950,6 +10957,8 @@ snapshots: dependencies: builtins: 1.0.3 + vite-bundle-analyzer@0.17.0: {} + vite@6.1.0(@types/node@22.12.0)(yaml@2.7.0): dependencies: esbuild: 0.24.2 diff --git a/vite.config.js b/vite.config.js index e217d6177..5137cc40c 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,11 +1,36 @@ +import path from "path"; + +import { analyzer } from "vite-bundle-analyzer"; + /** @type {import('vite').UserConfig} */ export default { + plugins: [analyzer()], server: { hmr: false, }, envDir: "./", build: { polyfillDynamicImport: false, + lib: { + entry: path.resolve(__dirname, "src/index.js"), + formats: ["es"], + fileName: (format) => `[name].js`, + }, + rollupOptions: { + external: [], // Add external dependencies here if any + output: { + preserveModules: true, + preserveModulesRoot: "src", + entryFileNames: "[name].js", + }, + }, + minify: "terser", + terserOptions: { + keep_classnames: true, + keep_fnames: true, + }, + sourcemap: true, + outDir: "lib", }, optimizeDeps: { force: true, @@ -29,9 +54,10 @@ export default { // will take care of this "../../src/index.js": "../../src/browser.js", "../src/index.js": "../src/browser.js", - // TODO: extract `encoding/hex.js` etc into a variable and call a function to generate + // TODO: extract `encoding/hex.js` etc into a variable and call a function to generate // all the prefixes. - "../../../src/encoding/hex.js": "../../../src/encoding/hex.browser.js", + "../../../src/encoding/hex.js": + "../../../src/encoding/hex.browser.js", "../../src/encoding/hex.js": "../../src/encoding/hex.browser.js", "../src/encoding/hex.js": "../src/encoding/hex.browser.js", "src/encoding/hex.js": "src/encoding/hex.browser.js", @@ -40,10 +66,13 @@ export default { "../src/encoding/utf8.js": "../src/encoding/utf8.browser.js", "../../src/encoding/utf8.js": "../../src/encoding/utf8.browser.js", "../encoding/utf8.js": "../encoding/utf8.browser.js", - "../src/cryptography/sha384.js": "../src/cryptography/sha384.browser.js", + "../src/cryptography/sha384.js": + "../src/cryptography/sha384.browser.js", "../cryptography/sha384.js": "../cryptography/sha384.browser.js", - "./client/NodeIntegrationTestEnv.js": "./client/WebIntegrationTestEnv.js", - "../integration/client/NodeIntegrationTestEnv.js": "../integration/client/WebIntegrationTestEnv.js", + "./client/NodeIntegrationTestEnv.js": + "./client/WebIntegrationTestEnv.js", + "../integration/client/NodeIntegrationTestEnv.js": + "../integration/client/WebIntegrationTestEnv.js", "../../src/client/NodeClient.js": "../../src/client/WebClient.js", }, },