-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildComponents.js
49 lines (41 loc) · 1.3 KB
/
buildComponents.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
const fs = require('fs');
const nodePath = require('path');
const { default: Parcel } = require('@parcel/core');
module.exports = class ComponentBundler {
entries = [];
static styleEntrypoints = ['static', 'component']
.reduce(
(acc, prefix) => acc.concat(
['scss', 'sass', 'css'].map(suffix => `${prefix}.${suffix}`),
),
[],
);
static getComponentFile(directory) {
return nodePath.join(directory, '/component.js');
}
constructor(componentDirectory) {
this.inputDir = componentDirectory;
this.addEntryPoint(this.inputFile);
}
get inputFile() {
return ComponentBundler.getComponentFile(this.inputDir);
}
addEntryPoint(entryPoint) {
this.entries.push(nodePath.resolve(entryPoint));
}
async bundle(outputDirectory) {
const { entries } = this;
let bundler = new Parcel({
entries,
distDir: outputDirectory,
defaultConfig: nodePath.join(__dirname, "parcelConfig.json"),
defaultEngines: {
browsers: ["defaults and supports custom-elementsv1"],
node: "14",
},
mode: "production",
sourceMaps: false,
});
await bundler.run();
}
}