-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
58 lines (45 loc) · 1.58 KB
/
scripts.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
const package = require(`${process.env.PWD}/package.json`);
const entrypoints = require(`${process.env.PWD}/entrypoints`);
const rollup = require('rollup');
const commonJs = require('@rollup/plugin-commonjs'); // Adds support for legacy CommonJS modules
const nodeResolve = require('@rollup/plugin-node-resolve'); // Uses the Node resolution algorithm for import declarations
const replace = require('@rollup/plugin-replace'); // Replaces strings, such as Node variables
const path = require('path');
/**
* Plugin configuration
*/
let plugins = {
replace: replace({
'preventAssignment': true,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
nodeResolve: nodeResolve({
browser: true,
moduleDirectories: [
'node_modules'
]
}),
commonJs: commonJs()
};
/**
* Executing function
*/
(async () => {
try {
for (let i = 0; i < entrypoints.length; i++) {
const script = entrypoints[i];
if (!script.hasOwnProperty('input') || path.extname(entrypoints[i].input) != '.js') continue;
console.log(`[${package.name}] Rolling up "${script.input.replace(process.env.PWD, '')}"`);
script.plugins = script.plugins
.map(p => typeof p === 'string' ? plugins[p] : p);
const bundle = await rollup.rollup(script);
for (let i = 0; i < script.output.length; i++) {
await bundle.write(script.output[i]);
}
bundle.close();
console.log(`[${package.name}] Rolled out to "${script.output[i].file.replace(process.env.PWD, '')}"`);
}
} catch (err) {
console.dir(err);
}
})();