-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.mjs
85 lines (77 loc) · 2.12 KB
/
build.mjs
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
// modify from https://souporserious.com/bundling-typescript-with-esbuild-for-npm/
//const { build } = require('esbuild')
//const { Generator } = require('npm-dts')
//const { dependencies, peerDependencies } = require('./package.json')
import { build } from "esbuild";
//import {Generator} from 'npm-dts'
import * as fs from "fs";
const loadJSON = (path) =>
JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
const mypackage = loadJSON("./package.json");
const dependencies = mypackage.dependencies;
//import {dependencies, peerDependencies } from './package.json' assert { type: "json" };
const entryFile = "src/index.ts";
const entryPoints = [entryFile];
const shared = {
entryPoints: [entryFile],
bundle: true,
external: Object.keys(dependencies),
define: { global: "window" },
};
build({
...shared,
outfile: "dist/index.js",
});
build({
...shared,
outfile: "dist/index.mjs",
format: "esm",
});
// build separate files for each module for easier use of part of sp and
// help with tree shaking???
const nonEntryPoints = [
"handlebarshelpers",
"leaflet_css",
"oregondsputil",
"scale",
"seismogramsegment",
"seismographconfig",
"seismographconfigeditor",
"sorting",
"spelement",
"util",
"vector",
"version",
].map((f) => `${f}.ts`);
const srcFiles = fs
.readdirSync("./src")
.filter((k) => k.endsWith(".ts"))
.filter((k) => !k.startsWith("index"))
.filter((k) => !nonEntryPoints.includes(k))
.map((f) => `src/${f}`);
console.log(`src files: ${srcFiles}`);
build({
entryPoints: srcFiles,
bundle: true,
platform: "neutral",
external: Object.keys(dependencies),
outdir: "dist/esm",
format: "esm",
});
// without leaflet for node (leaflet requires window global)
const nodeEntryFile = "src/index_node.ts";
const nodeDependencies = Object.keys(dependencies).filter(
(k) => k !== "leaflet" && k !== "leafletutil",
);
console.log(`deps: ${nodeDependencies}`);
build({
entryPoints: [nodeEntryFile],
bundle: true,
external: nodeDependencies,
outfile: "dist/index_node.mjs",
format: "esm",
});
// new Generator({
// entry: entryFile,
// output: 'dist/index.d.ts',
// }).generate()