Skip to content

Commit 35fe566

Browse files
authored
chore(build): streamline all vite.config external options (#2214)
1 parent 7b23b74 commit 35fe566

File tree

15 files changed

+243
-169
lines changed

15 files changed

+243
-169
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@
141141
"y-partykit": "^0.0.33",
142142
"yjs": "^13.6.27"
143143
}
144-
}
144+
}

packages/ariakit/vite.config.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,26 @@ export default defineConfig((conf) => ({
3737
rollupOptions: {
3838
// make sure to externalize deps that shouldn't be bundled
3939
// into your library
40-
external: [
41-
...Object.keys({
42-
...pkg.dependencies,
43-
...pkg.peerDependencies,
44-
...pkg.devDependencies,
45-
}),
46-
"react/jsx-runtime",
47-
],
40+
external: (source) => {
41+
if (
42+
Object.keys({
43+
...pkg.dependencies,
44+
...((pkg as any).peerDependencies || {}),
45+
...pkg.devDependencies,
46+
}).includes(source)
47+
) {
48+
return true;
49+
}
50+
return (
51+
source.startsWith("react/") ||
52+
source.startsWith("react-dom/") ||
53+
source.startsWith("prosemirror-") ||
54+
source.startsWith("@tiptap/") ||
55+
source.startsWith("@blocknote/") ||
56+
source.startsWith("@shikijs/") ||
57+
source.startsWith("node:")
58+
);
59+
},
4860
output: {
4961
// Provide global variables to use in the UMD build
5062
// for externalized deps

packages/code-block/vite.config.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { defineConfig } from "vite";
44
import pkg from "./package.json";
55
// import eslintPlugin from "vite-plugin-eslint";
66

7-
const deps = Object.keys({
8-
...pkg.dependencies,
9-
...pkg.peerDependencies,
10-
...pkg.devDependencies,
11-
});
7+
128

139
// https://vitejs.dev/config/
1410
export default defineConfig((conf) => ({
@@ -41,16 +37,25 @@ export default defineConfig((conf) => ({
4137
rollupOptions: {
4238
// make sure to externalize deps that shouldn't be bundled
4339
// into your library
44-
external: (source: string) => {
45-
if (deps.includes(source)) {
40+
external: (source) => {
41+
if (
42+
Object.keys({
43+
...pkg.dependencies,
44+
...((pkg as any).peerDependencies || {}),
45+
...pkg.devDependencies,
46+
}).includes(source)
47+
) {
4648
return true;
4749
}
48-
49-
if (source.startsWith("@shikijs/")) {
50-
return true;
51-
}
52-
53-
return false;
50+
return (
51+
source.startsWith("react/") ||
52+
source.startsWith("react-dom/") ||
53+
source.startsWith("prosemirror-") ||
54+
source.startsWith("@tiptap/") ||
55+
source.startsWith("@blocknote/") ||
56+
source.startsWith("@shikijs/") ||
57+
source.startsWith("node:")
58+
);
5459
},
5560
output: {
5661
// Provide global variables to use in the UMD build

packages/core/vite.config.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfig } from "vitest/config";
44
import pkg from "./package.json";
55
// import eslintPlugin from "vite-plugin-eslint";
66

7-
const deps = Object.keys(pkg.dependencies);
7+
88

99
// https://vitejs.dev/config/
1010
export default defineConfig({
@@ -32,14 +32,24 @@ export default defineConfig({
3232
rollupOptions: {
3333
// make sure to externalize deps that shouldn't be bundled
3434
// into your library
35-
external: (source: string) => {
36-
if (deps.includes(source)) {
35+
external: (source) => {
36+
if (
37+
Object.keys({
38+
...pkg.dependencies,
39+
...((pkg as any).peerDependencies || {}),
40+
...pkg.devDependencies,
41+
}).includes(source)
42+
) {
3743
return true;
3844
}
3945
return (
46+
source.startsWith("react/") ||
47+
source.startsWith("react-dom/") ||
4048
source.startsWith("prosemirror-") ||
41-
source.startsWith("@shikijs/lang") ||
42-
source.startsWith("@shikijs/theme")
49+
source.startsWith("@tiptap/") ||
50+
source.startsWith("@blocknote/") ||
51+
source.startsWith("@shikijs/") ||
52+
source.startsWith("node:")
4353
);
4454
},
4555
output: {

packages/mantine/vite.config.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,26 @@ export default defineConfig((conf) => ({
3737
rollupOptions: {
3838
// make sure to externalize deps that shouldn't be bundled
3939
// into your library
40-
external: [
41-
...Object.keys({
42-
...pkg.dependencies,
43-
...pkg.peerDependencies,
44-
...pkg.devDependencies,
45-
}),
46-
"react/jsx-runtime",
47-
],
40+
external: (source) => {
41+
if (
42+
Object.keys({
43+
...pkg.dependencies,
44+
...((pkg as any).peerDependencies || {}),
45+
...pkg.devDependencies,
46+
}).includes(source)
47+
) {
48+
return true;
49+
}
50+
return (
51+
source.startsWith("react/") ||
52+
source.startsWith("react-dom/") ||
53+
source.startsWith("prosemirror-") ||
54+
source.startsWith("@tiptap/") ||
55+
source.startsWith("@blocknote/") ||
56+
source.startsWith("@shikijs/") ||
57+
source.startsWith("node:")
58+
);
59+
},
4860
output: {
4961
// Provide global variables to use in the UMD build
5062
// for externalized deps

packages/react/vite.config.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,22 @@ export default defineConfig((conf) => ({
3838
// into your library
3939
external: (source) => {
4040
if (
41-
[
42-
...Object.keys({
43-
...pkg.dependencies,
44-
...pkg.peerDependencies,
45-
...pkg.devDependencies,
46-
}),
47-
"react-dom/client",
48-
"react/jsx-runtime",
49-
].includes(source)
41+
Object.keys({
42+
...pkg.dependencies,
43+
...((pkg as any).peerDependencies || {}),
44+
...pkg.devDependencies,
45+
}).includes(source)
5046
) {
5147
return true;
5248
}
53-
5449
return (
50+
source.startsWith("react/") ||
51+
source.startsWith("react-dom/") ||
5552
source.startsWith("prosemirror-") ||
5653
source.startsWith("@tiptap/") ||
57-
source.startsWith("@blocknote/")
54+
source.startsWith("@blocknote/") ||
55+
source.startsWith("@shikijs/") ||
56+
source.startsWith("node:")
5857
);
5958
},
6059
output: {

packages/server-util/vite.config.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { defineConfig } from "vite";
44
import pkg from "./package.json";
55
// import eslintPlugin from "vite-plugin-eslint";
66

7-
const deps = Object.keys({
8-
...pkg.dependencies,
9-
...pkg.peerDependencies,
10-
...pkg.devDependencies,
11-
});
7+
128

139
// https://vitejs.dev/config/
1410
export default defineConfig((conf) => ({
@@ -41,15 +37,26 @@ export default defineConfig((conf) => ({
4137
rollupOptions: {
4238
// make sure to externalize deps that shouldn't be bundled
4339
// into your library
44-
external: [
45-
...Object.keys({
46-
...pkg.dependencies,
47-
...pkg.peerDependencies,
48-
...pkg.devDependencies,
49-
}),
50-
"react-dom/client",
51-
"react/jsx-runtime",
52-
],
40+
external: (source) => {
41+
if (
42+
Object.keys({
43+
...pkg.dependencies,
44+
...((pkg as any).peerDependencies || {}),
45+
...pkg.devDependencies,
46+
}).includes(source)
47+
) {
48+
return true;
49+
}
50+
return (
51+
source.startsWith("react/") ||
52+
source.startsWith("react-dom/") ||
53+
source.startsWith("prosemirror-") ||
54+
source.startsWith("@tiptap/") ||
55+
source.startsWith("@blocknote/") ||
56+
source.startsWith("@shikijs/") ||
57+
source.startsWith("node:")
58+
);
59+
},
5360
output: {
5461
// Provide global variables to use in the UMD build
5562
// for externalized deps

packages/shadcn/vite.config.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,26 @@ export default defineConfig((conf) => ({
4040
rollupOptions: {
4141
// make sure to externalize deps that shouldn't be bundled
4242
// into your library
43-
external: [
44-
...Object.keys({
45-
...pkg.dependencies,
46-
...pkg.peerDependencies,
47-
...pkg.devDependencies,
48-
}),
49-
"react/jsx-runtime",
50-
],
43+
external: (source) => {
44+
if (
45+
Object.keys({
46+
...pkg.dependencies,
47+
...((pkg as any).peerDependencies || {}),
48+
...pkg.devDependencies,
49+
}).includes(source)
50+
) {
51+
return true;
52+
}
53+
return (
54+
source.startsWith("react/") ||
55+
source.startsWith("react-dom/") ||
56+
source.startsWith("prosemirror-") ||
57+
source.startsWith("@tiptap/") ||
58+
source.startsWith("@blocknote/") ||
59+
source.startsWith("@shikijs/") ||
60+
source.startsWith("node:")
61+
);
62+
},
5163
output: {
5264
// Provide global variables to use in the UMD build
5365
// for externalized deps

packages/xl-ai-server/vite.config.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,26 @@ export default defineConfig((conf) => ({
3232
rollupOptions: {
3333
// make sure to externalize deps that shouldn't be bundled
3434
// into your library
35-
external: [
36-
...Object.keys({
37-
...pkg.dependencies,
38-
...pkg.peerDependencies,
39-
...pkg.devDependencies,
40-
}),
41-
"node:fs",
42-
"node:http2",
43-
],
35+
external: (source) => {
36+
if (
37+
Object.keys({
38+
...pkg.dependencies,
39+
...((pkg as any).peerDependencies || {}),
40+
...pkg.devDependencies,
41+
}).includes(source)
42+
) {
43+
return true;
44+
}
45+
return (
46+
source.startsWith("react/") ||
47+
source.startsWith("react-dom/") ||
48+
source.startsWith("prosemirror-") ||
49+
source.startsWith("@tiptap/") ||
50+
source.startsWith("@blocknote/") ||
51+
source.startsWith("@shikijs/") ||
52+
source.startsWith("node:")
53+
);
54+
},
4455
output: {
4556
// Provide global variables to use in the UMD build
4657
// for externalized deps

packages/xl-ai/vite.config.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,22 @@ export default defineConfig((conf) => ({
4747
// into your library
4848
external: (source) => {
4949
if (
50-
[
51-
...Object.keys({
52-
...pkg.dependencies,
53-
...pkg.peerDependencies,
54-
...pkg.devDependencies,
55-
}),
56-
"react-dom/client",
57-
"react/jsx-runtime",
58-
].includes(source)
50+
Object.keys({
51+
...pkg.dependencies,
52+
...((pkg as any).peerDependencies || {}),
53+
...pkg.devDependencies,
54+
}).includes(source)
5955
) {
6056
return true;
6157
}
62-
6358
return (
59+
source.startsWith("react/") ||
60+
source.startsWith("react-dom/") ||
6461
source.startsWith("prosemirror-") ||
6562
source.startsWith("@tiptap/") ||
66-
source.startsWith("@blocknote/")
63+
source.startsWith("@blocknote/") ||
64+
source.startsWith("@shikijs/") ||
65+
source.startsWith("node:")
6766
);
6867
},
6968
output: {

0 commit comments

Comments
 (0)