Skip to content

Commit 595ecf3

Browse files
authored
Add build target option to the custom component gradio.config.js file (#8520)
1 parent de6aa2b commit 595ecf3

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

.changeset/cold-donkeys-jump.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gradio/preview": minor
3+
"gradio": minor
4+
---
5+
6+
feat:Add build target option to the custom component `gradio.config.js` file

gradio/cli/commands/components/files/gradio.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ export default {
33
svelte: {
44
preprocess: [],
55
},
6+
build: {
7+
target: "modules",
8+
},
69
};

guides/06_custom-components/05_frontend.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ Vite options:
267267
Svelte options:
268268
- `preprocess`: A list of svelte preprocessors to use.
269269
- `extensions`: A list of file extensions to compile to `.svelte` files.
270+
- `build.target`: The target to build for, this may be necessary to support newer javascript features. See the [esbuild docs](https://esbuild.github.io/api/#target) for more information.
270271

271272
The `gradio.config.js` file should be placed in the root of your component's `frontend` directory. A default config file is created for you when you create a new component. But you can also create your own config file, if one doesn't exist, and use it to customize your component's build process.
272273

js/preview/src/build.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export async function make_build({
3737
plugins: [],
3838
svelte: {
3939
preprocess: []
40+
},
41+
build: {
42+
target: []
4043
}
4144
};
4245

@@ -48,6 +51,7 @@ export async function make_build({
4851

4952
component_config.plugins = m.default.plugins || [];
5053
component_config.svelte.preprocess = m.default.svelte?.preprocess || [];
54+
component_config.build.target = m.default.build?.target || "modules";
5155
}
5256

5357
const exports: string[][] = [
@@ -65,6 +69,7 @@ export async function make_build({
6569
make_gradio_plugin({ mode: "build", svelte_dir })
6670
],
6771
build: {
72+
target: component_config.build.target,
6873
emptyOutDir: true,
6974
outDir: join(template_dir, entry),
7075
lib: {

js/preview/src/dev.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export async function create_server({
5757
allow: [root_dir, component_dir]
5858
}
5959
},
60+
build: {
61+
target: config.build.target
62+
},
6063
plugins: [
6164
...plugins(config),
6265
make_gradio_plugin({
@@ -116,6 +119,9 @@ export interface ComponentConfig {
116119
preprocess: PreprocessorGroup[];
117120
extensions?: string[];
118121
};
122+
build: {
123+
target: string | string[];
124+
};
119125
}
120126

121127
async function generate_imports(
@@ -134,10 +140,13 @@ async function generate_imports(
134140
);
135141
}
136142

137-
let component_config = {
143+
let component_config: ComponentConfig = {
138144
plugins: [],
139145
svelte: {
140146
preprocess: []
147+
},
148+
build: {
149+
target: []
141150
}
142151
};
143152

@@ -153,6 +162,7 @@ async function generate_imports(
153162

154163
component_config.plugins = m.default.plugins || [];
155164
component_config.svelte.preprocess = m.default.svelte?.preprocess || [];
165+
component_config.build.target = m.default.build?.target || "modules";
156166
} else {
157167
}
158168
})

js/preview/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type ChildProcess, spawn, spawnSync } from "node:child_process";
22
import * as net from "net";
33

4-
import { create_server } from "./dev";
4+
import { create_server, type ComponentConfig } from "./dev";
55
import { make_build } from "./build";
66
import { join, dirname } from "path";
77
import { fileURLToPath } from "url";

0 commit comments

Comments
 (0)