-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathbuildPackage.js
68 lines (57 loc) · 1.71 KB
/
buildPackage.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
/** @todo Refactor this module to not have side effects */
const path = require("path");
const { rollup } = require("rollup");
const { babel } = require("@rollup/plugin-babel");
const commonjs = require("@rollup/plugin-commonjs");
const { nodeResolve } = require("@rollup/plugin-node-resolve");
const json = require("@rollup/plugin-json");
const svgr = require("@svgr/rollup");
const createBuildPreset = require("@weave-design/babel-preset/build");
const createExternalDeterminer = require("./createExternalDeterminer");
/* eslint-disable-next-line import/no-dynamic-require */
const packageMeta = require(path.resolve(process.cwd(), "package.json"));
const {
name: packageName,
version: packageVersion,
peerDependencies = {},
dependencies = {},
main: mainOutputFile = "build/index.js",
module: esOutputFile = "build/index.es.js"
} = packageMeta;
const externalDependencies = Object.keys(peerDependencies).concat(
Object.keys(dependencies)
);
const inputOptions = {
input: "src/index.js",
external: createExternalDeterminer(externalDependencies),
plugins: [
nodeResolve(),
svgr.default(),
json(),
babel({
babelrc: false,
babelHelpers: 'bundled',
...createBuildPreset()
}),
commonjs()
]
};
const esModulesOutputOptions = {
name: "HIG",
file: esOutputFile,
format: "es"
};
const cjsOutputOptions = {
file: mainOutputFile,
format: "cjs",
exports: "named"
};
module.exports = async function buildPackage() {
/* eslint-disable-next-line no-console */
console.log(`Bundling ${packageName} v${packageVersion}.`);
const bundle = await rollup(inputOptions);
return Promise.all([
bundle.write(esModulesOutputOptions),
bundle.write(cjsOutputOptions)
]);
};