Skip to content

Commit d2579ab

Browse files
Wauplincoyotte508
andauthored
Do not export ./snippets module in browser mode (#1259)
⚠️ PR opened on top of #1255 Related to this thread #1255 (comment). @coyotte508 @SBrandeis @julien-c WDYT? 🙈 for the record, I'm looking for a solution where: 1. we keep this public/open-source 2. we keep the structure of jinja templates 3. ideally no new package in hf.js 4. ideally no new tooling (e.g. to translate jinja into TS code) ~Solution here is simply to gracefully raise an error if environment not supported.~ **EDIT:** based on #1259 (comment), goal is to not package the `./snippets` module in browser mode. --------- Co-authored-by: coyotte508 <[email protected]>
1 parent 99e8c87 commit d2579ab

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

packages/inference/package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@
3333
"main": "./dist/index.cjs",
3434
"module": "./dist/index.js",
3535
"exports": {
36-
"types": "./dist/src/index.d.ts",
37-
"require": "./dist/index.cjs",
38-
"import": "./dist/index.js"
36+
".": {
37+
"types": "./dist/src/index.d.ts",
38+
"require": "./dist/index.cjs",
39+
"import": "./dist/index.js"
40+
}
41+
},
42+
"browser": {
43+
"./src/snippets/index.js": false,
44+
"./dist/index.js": "./dist/browser/index.js",
45+
"./dist/index.mjs": "./dist/browser/index.mjs"
3946
},
4047
"type": "module",
4148
"scripts": {

packages/inference/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export { InferenceClient, InferenceClientEndpoint, HfInference } from "./Inferen
22
export { InferenceOutputError } from "./lib/InferenceOutputError";
33
export * from "./types";
44
export * from "./tasks";
5-
65
import * as snippets from "./snippets/index.js";
6+
77
export { snippets };

packages/inference/tsup.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { Options } from "tsup";
2+
3+
const baseConfig: Options = {
4+
entry: ["./index.ts"],
5+
format: ["cjs", "esm"],
6+
outDir: "dist",
7+
clean: true,
8+
};
9+
10+
const nodeConfig: Options = {
11+
...baseConfig,
12+
platform: "node",
13+
};
14+
15+
const browserConfig: Options = {
16+
...baseConfig,
17+
platform: "browser",
18+
target: "es2018",
19+
splitting: true,
20+
outDir: "dist/browser",
21+
};
22+
23+
export default [nodeConfig, browserConfig];

0 commit comments

Comments
 (0)