Skip to content

Commit bb8e06e

Browse files
committed
bundle the library with vite, because the worker requires being bundled
1 parent 1e21db6 commit bb8e06e

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"exports": {
1414
".": {
1515
"types": "./lib/index.d.ts",
16-
"import": "./lib/index.js"
17-
},
18-
"./*": "./lib/*"
16+
"import": "./lib/index.es.min.js",
17+
"require": "./lib/index.umd.min.js"
18+
}
1919
},
2020
"bin": {
2121
"hyp": "bin/cli.js",
@@ -28,16 +28,16 @@
2828
],
2929
"scripts": {
3030
"build:ts": "tsc -b",
31-
"build:vite": "vite build",
32-
"build": "run-s build:ts build:vite",
33-
"postbuild": "copyfiles -u 1 src/**/*.css lib/",
34-
"coverage": "vitest run --coverage --coverage.include=src --coverage.include=bin",
31+
"build:lib": "vite build -c vite.lib.config.ts",
32+
"build:app": "vite build -c vite.app.config.ts",
33+
"build": "run-s build:ts build:lib build:app",
34+
"coverage": "vitest run -c vite.lib.config.ts --coverage --coverage.include=src --coverage.include=bin",
3535
"dev": "run-p -l watch:ts watch:vite watch:serve",
3636
"lint": "eslint .",
3737
"prepublishOnly": "npm run build",
3838
"serve": "node bin/cli.js",
3939
"preserve": "npm run build",
40-
"test": "vitest run",
40+
"test": "vitest run -c vite.lib.config.ts",
4141
"typecheck": "tsc --noEmit",
4242
"url": "run-p -l watch:ts watch:vite watch:url",
4343
"watch:ts": "tsc --watch",
@@ -59,7 +59,6 @@
5959
"@types/react-dom": "19.0.3",
6060
"@vitejs/plugin-react": "4.3.4",
6161
"@vitest/coverage-v8": "3.0.7",
62-
"copyfiles": "2.4.1",
6362
"eslint": "9.21.0",
6463
"eslint-plugin-react": "7.37.4",
6564
"eslint-plugin-react-hooks": "5.1.0",

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
"rootDir": "src",
2121
"outDir": "./lib",
22-
"noEmit": false,
23-
"emitDeclarationOnly": false,
22+
"noEmit": true,
23+
"emitDeclarationOnly": true,
2424
"declaration": true
2525
},
2626
"include": ["src"]

vite.config.ts renamed to vite.app.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ import { defineConfig } from 'vite'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7-
test: { environment: 'jsdom', globals: true },
87
})

vite.lib.config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference types="vitest/config" />
2+
import react from '@vitejs/plugin-react'
3+
import { resolve } from 'path'
4+
import { defineConfig } from 'vite'
5+
6+
// https://vite.dev/config/
7+
export default defineConfig({
8+
plugins: [react()],
9+
build: {
10+
outDir: resolve(__dirname, 'lib'),
11+
copyPublicDir: false,
12+
lib: {
13+
entry: resolve(__dirname, 'src/index.ts'),
14+
formats: ['es', 'umd'],
15+
name: 'Hyperparam',
16+
fileName: (format) => `index.${format}.min.js`,
17+
},
18+
rollupOptions: {
19+
external: ['react', 'react/jsx-runtime', 'react-dom'],
20+
output: {
21+
globals: {
22+
react: 'React',
23+
'react/jsx-runtime': 'jsx',
24+
'react-dom': 'ReactDOM',
25+
},
26+
},
27+
},
28+
sourcemap: true,
29+
},
30+
test: { environment: 'jsdom', globals: true },
31+
})

0 commit comments

Comments
 (0)