From e3ea969ac6cb8b2b53593c20cb4d28a38dbf6b7e Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Mon, 16 Oct 2023 10:07:09 +0200 Subject: [PATCH] Enable code splitting --- package.json | 3 +-- tsconfig.build.json | 1 + tsup.config.ts | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index cff071334..fb4557257 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "bugs": { "url": "https://github.com/MetaMask/utils/issues" }, + "sideEffects": false, "repository": { "type": "git", "url": "https://github.com/MetaMask/utils.git" @@ -19,8 +20,6 @@ }, "./package.json": "./package.json" }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", "types": "./dist/types/index.d.ts", "files": [ "dist" diff --git a/tsconfig.build.json b/tsconfig.build.json index d3ee1aece..514d6fe82 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -18,6 +18,7 @@ "./src/**/__tests__/**/*", "./src/**/__snapshots__/**/*", "./src/**/*.test.ts", + "./src/**/*.test-d.ts", "./src/**/*.test.*.ts" ] } diff --git a/tsup.config.ts b/tsup.config.ts index 5b340afeb..979f8d01f 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -2,7 +2,17 @@ import { defineConfig } from 'tsup'; export default defineConfig({ // The entry to bundle. - entry: ['src/index.ts'], + entry: [ + 'src/**/*.ts', + '!src/**/__fixtures__/**/*', + '!src/**/__mocks__/**/*', + '!src/**/__test__/**/*', + '!src/**/__tests__/**/*', + '!src/**/__snapshots__/**/*', + '!src/**/*.test.ts', + '!src/**/*.test-d.ts', + '!src/**/*.test.*.ts', + ], // The output formats. We want to generate both CommonJS and ESM bundles. // https://tsup.egoist.dev/#bundle-formats @@ -18,9 +28,13 @@ export default defineConfig({ // Enables shimming of `__dirname` and `import.meta.url`, so that they work // in both CommonJS and ESM. // https://tsup.egoist.dev/#inject-cjs-and-esm-shims - shims: true, + shims: false, // Hide unnecessary logs from the console. Warnings and errors will still be // shown. silent: true, + + // Split the output into chunks. This is useful for tree-shaking. + // https://tsup.egoist.dev/#code-splitting + splitting: true, });