summaryrefslogtreecommitdiff
path: root/vite.config.ts
diff options
context:
space:
mode:
authorPawel Zelawski <pawel.zelawski@outlook.com>2025-04-09 20:33:24 +0200
committerPawel Zelawski <pawel.zelawski@outlook.com>2025-04-09 20:33:24 +0200
commit2350aa140eb692610cc8ba1788ac0300188a5144 (patch)
tree97f71119313f79ab690f1b9ca99aaec34ec35599 /vite.config.ts
parenta45bcd5f84b2e7be982e170aa31f64afac61a337 (diff)
build: Configure Vite for library build and finalize package fields
- Add `vite-plugin-dts` dev dependency. - Create `vite.config.ts` specifically for library build mode: - Configure ESM and UMD outputs (`dist/digiid-ts.es.js`, `dist/digiid-ts.umd.js`). - Set up `vite-plugin-dts` for generating `dist/index.d.ts`. - Externalize Node.js built-ins and 'digibyte-message' dependency. - Update `package.json`: - Change `scripts.build` to `vite build`. - Point `main`, `module`, and `types` fields to the correct files in `dist/`. - Run and verify the build process successfully generates the expected distribution files.
Diffstat (limited to 'vite.config.ts')
-rw-r--r--vite.config.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/vite.config.ts b/vite.config.ts
new file mode 100644
index 0000000..a69cc50
--- /dev/null
+++ b/vite.config.ts
@@ -0,0 +1,37 @@
+import { defineConfig } from 'vite';
+import dts from 'vite-plugin-dts'; // Plugin to generate consolidated .d.ts file
+import { resolve } from 'path';
+
+// https://vitejs.dev/guide/build.html#library-mode
+export default defineConfig({
+ plugins: [
+ dts({ // Generate declaration files
+ insertTypesEntry: true, // Create a single entry point for types
+ }),
+ ],
+ build: {
+ lib: {
+ // Could also be a dictionary or array of multiple entry points
+ entry: resolve(__dirname, 'src/index.ts'),
+ name: 'DigiIDTs', // Global variable name in UMD build
+ formats: ['es', 'umd'], // Output formats (ES Module, Universal Module Definition)
+ fileName: (format) => `digiid-ts.${format}.js`, // Output file names
+ },
+ rollupOptions: {
+ // Make sure to externalize deps that shouldn't be bundled
+ // into your library (e.g., peer dependencies)
+ external: ['crypto', 'module', 'digibyte-message'], // Externalize Node built-ins and the core dependency
+ output: {
+ // Provide global variables to use in the UMD build
+ // for externalized deps
+ globals: {
+ crypto: 'crypto', // Map 'crypto' import to global 'crypto' (Node)
+ module: 'module', // Map 'module' import to global 'module' (Node)
+ 'digibyte-message': 'DigibyteMessage' // Example global name if needed, might not be necessary for UMD if only used internally
+ },
+ },
+ },
+ sourcemap: true, // Generate source maps for debugging
+ emptyOutDir: true, // Clean the dist directory before building
+ },
+}); \ No newline at end of file