diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 05cf5a6..784036c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,11 +10,11 @@ jobs: # Setup .npmrc file to publish to npm - uses: actions/setup-node@v4 with: - node-version: '20.x' - registry-url: 'https://registry.npmjs.org' + node-version: "20.x" + registry-url: "https://registry.npmjs.org" - uses: oven-sh/setup-bun@v2 - run: bun install - run: bun run build-designsystem - - run: cd dist && npm publish --access=public + - run: cd packages/lib/dist && npm publish env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/packages/lib/build.ts b/packages/lib/build.ts index 873298e..529b771 100644 --- a/packages/lib/build.ts +++ b/packages/lib/build.ts @@ -2,16 +2,22 @@ import esbuild from 'esbuild'; import { dtsPlugin } from 'esbuild-plugin-d.ts'; import litPlugin from 'esbuild-plugin-lit'; -import { dependencies } from './package.json'; +import { dependencies, peerDependencies } from './package.json'; esbuild.build({ - entryPoints: ['components/**/(index|react).ts'], + entryPoints: ['components/**/index.ts', 'components/**/react.ts'], outdir: 'dist', bundle: true, sourcemap: true, - metafile: true, outbase: 'components', + allowOverwrite: true, format: 'esm', plugins: [litPlugin(), dtsPlugin({ tsconfig: 'tsconfig.lib.json' })], - external: [...Object.keys(dependencies)], + + /** + * The React wrappers import the web component from the index file. + * We do not want to bundle the web component into the react entry point, + * so we exclude all imports of "./index" from the bundle. + */ + external: [...Object.keys(dependencies), ...Object.keys(peerDependencies), './index*'], }); diff --git a/packages/lib/package.json b/packages/lib/package.json index 6e7e68c..54e3074 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "bun run build-components && bun run build-global-styles", "build-global-styles": "tsup global-styles.css --out-dir dist", - "build-components": "rm -rf dist && bun build.ts", + "build-components": "bun build.ts", "create-icon-registry": "svg-to-ts-constants" }, "dependencies": { @@ -13,6 +13,9 @@ "@lit/react": "^1.0.6", "lit": "^3.2.1" }, + "peerDependencies": { + "react": ">=18.0.0 <20.0.0" + }, "devDependencies": { "@types/node": "^22.10.2", "esbuild": "^0.24.0",