-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrollup.config.js
74 lines (69 loc) · 1.89 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
import commonjs from "@rollup/plugin-commonjs";
import sourceMaps from "rollup-plugin-sourcemaps";
import nodeResolve from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json";
import { readFileSync, writeFileSync, copyFileSync } from "fs";
import nodePolyfills from "rollup-plugin-node-polyfills";
import pkg from "./package.json";
let numberOfBundlesBuilt = 0;
let outputBundles = [
{
file: "./dist/dist/twelvedata.js",
format: "umd",
name: pkg.name,
},
{
file: "./dist/dist-esm/twelvedata.js",
format: "es",
},
];
export function initRollupPostScript() {
try {
// Read internal packagejson and create public package json
const internalPackageJson = JSON.parse(readFileSync(`./package.json`));
delete internalPackageJson.scripts;
delete internalPackageJson.devDependencies;
delete internalPackageJson.jest;
delete internalPackageJson.files;
delete internalPackageJson.source;
writeFileSync(
`./dist/package.json`,
JSON.stringify(internalPackageJson, null, 2)
);
copyFileSync("README.md", "dist/README.md");
copyFileSync("LICENSE.txt", "dist/LICENSE.txt");
} catch (Error) {
console.error("Post script failed", Error);
}
}
export default {
input: "index.js",
output: outputBundles,
external: ["cross-fetch", "cross-fetch/polyfill"],
plugins: [
sourceMaps(),
nodePolyfills(),
nodeResolve({
mainFields: ["jsnext", "main"],
preferBuiltins: true,
browser: true,
}),
commonjs({
include: "node_modules/**",
}),
json({
compact: true,
}),
{
name: "buildHooks",
writeBundle() {
numberOfBundlesBuilt++;
if (numberOfBundlesBuilt === outputBundles.length) {
console.log("Done with Bundles. Running post script");
initRollupPostScript();
numberOfBundlesBuilt = 0;
}
},
},
],
};