-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
79 lines (75 loc) · 2.1 KB
/
vite.config.ts
File metadata and controls
79 lines (75 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import assert from "assert"
import { existsSync, readdirSync } from "fs"
import { resolve } from "path"
import dts from "vite-plugin-dts"
import tsconfigPaths from "vite-tsconfig-paths"
import { defineConfig } from "vitest/config"
import packageJson from "./package.json"
// Generate entry points by looking at package.json's `exports` field. For each
//
// foo: {types: .., import: ..}
//
// - types must be "./dist/foo.d.ts"
// - import must be "./dist/foo.js"
// - file src/exports/foo.ts must exist
//
// Collect all path src/exports/foo.ts.
const entry = Object.entries(packageJson.exports).map(([key, value]) => {
const name = key === "." ? "index" : key.slice(2)
const path = resolve(__dirname, "src/exports", `${name}.ts`)
console.debug(path)
assert(
existsSync(path),
`export ${name} in package.json requires file ${path} to exist; missing`,
)
assert(
value.types === `./dist/${name}.d.ts` &&
value.import === `./dist/${name}.js`,
`export ${name} in package.json requires types to be "./dist/${name}.d.ts"`,
)
return path
})
// make sure we have the same number of files in src/exports as in package.json `exports` field
assert(
readdirSync(resolve(__dirname, "src/exports")).length ===
Object.keys(packageJson.exports).length,
"src/exports has more files than package.json `exports` field; update package.json or remove file",
)
export default defineConfig({
assetsInclude: ["**/*.wasm", "**/*.js"],
build: {
sourcemap: false,
lib: {
name: "@audiotool/nexus",
entry,
formats: ["es"],
},
rollupOptions: {
external: [
"@bufbuild/protobuf",
"@connectrpc/connect",
"@connectrpc/connect-web",
"@connectrpc/connect-node",
"toposort",
"utility-types",
"uuid",
"zod",
/^node:/,
],
output: {
entryFileNames: "[name].js",
},
},
// inline assets up to 1MB
assetsInlineLimit: 1024 * 1024,
},
test: {
setupFiles: ["./src/testing/test-setup.ts"],
},
plugins: [
tsconfigPaths(),
dts({
insertTypesEntry: true,
}),
],
})