-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
103 lines (99 loc) · 2.67 KB
/
rollup.config.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// rollup.config.js
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import replace from "@rollup/plugin-replace";
import json from "@rollup/plugin-json";
import { terser } from "rollup-plugin-terser";
// Node.js configuration
const nodeESMConfig = {
input: {
index: "src/index.ts",
json_store: "src/json_store.ts",
json_parser: "src/json_parser.ts",
}, // change to your entry point TS file
output: {
dir: "dist/node",
format: "esm",
sourcemap: false,
entryFileNames: "[name].js", // Outputs index.js, JSONstore.js
},
plugins: [
typescript({
tsconfig: "./tsconfig.json",
declaration: true,
declarationDir: "dist/node/types",
}), // ensure you have the correct path to your tsconfig.json
json(),
terser(),
// Add any other rollup plugins that you may need
],
external: ["node-fetch", "stream"],
};
// Browser configuration
const browserESMConfig = {
input: {
index: "src/index.ts",
json_store: "src/json_store.ts",
json_parser: "src/json_parser.ts",
}, // change to your entry point TS file
output: {
dir: "dist/browser",
format: "esm",
sourcemap: false,
entryFileNames: "[name].js", // Outputs index.js, JSONstore.js
},
plugins: [
typescript({
tsconfig: "./tsconfig.json",
declaration: false,
// declarationDir: "dist/browser/types",
}), // ensure you have the correct path to your tsconfig.json
resolve({ browser: true }),
commonjs(),
json(),
replace({
"node-fetch": "fetch", // Replace node-fetch with window.fetch in the browser build
preventAssignment: true,
}),
terser(),
// Add any other rollup plugins that you may need
],
};
const iifeConfig = (name, isMain = false, output_filename) => {
const outputName = isMain ? "OllamaJS" : `OllamaJS_${name}`;
return {
input: `src/${name}.ts`,
output: {
file: `dist/browser/iife/${output_filename || name}.global.js`,
format: "iife",
name: outputName,
extend: true,
globals: {
fetch: "fetch",
},
sourcemap: false,
},
plugins: [
typescript({
tsconfig: "./tsconfig.json",
declaration: false,
}),
resolve({ browser: true }),
commonjs(),
json(),
replace({
"node-fetch": "fetch",
preventAssignment: true,
}),
terser(),
],
};
};
export default [
nodeESMConfig,
browserESMConfig,
iifeConfig("index", true, "ollama-js"),
iifeConfig("json_store", false, "ollama-js-json-store"),
iifeConfig("json_parser", false, "ollama-js-json-parser"),
];