-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
66 lines (59 loc) · 1.8 KB
/
build.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
const rollup = require("rollup"),
chalk = require("chalk"),
babel = require("rollup-plugin-babel"),
resolve = require("@rollup/plugin-node-resolve"),
{uglify} = require("rollup-plugin-uglify"),
pkg = require("./package.json");
const destination = "dist/";
// const warnHandler = (info) => {
// console.info(chalk.yellow(`encountered rollup warning for: ${info.loc}`), info);
// };
const doRollup = (config) =>
rollup.rollup(config)
.then((bundle) => bundle.write(config));
const input = "lib/index.js";
const outputConfig = {
name: "htmlDirContent",
format: "umd",
sourcemap: "inline",
banner: `/* html-dir-content v${pkg.version} (c) ${new Date().getFullYear()}, Yoav Niran, https://github.com/yoavniran/html-dir-content.git/blob/master/LICENSE */`,
};
const plugins = [
resolve(),
babel({ exclude: "node_modules/**" })
];
Promise.all([
doRollup({ //----------- DEV
input,
output: {
...outputConfig,
file: (destination + "html-dir-content.js")
},
plugins,
}),
doRollup({ //------------ PROD
input,
output: {
...outputConfig,
sourcemap: true,
file: (destination + "html-dir-content.min.js")
},
plugins: [
...plugins,
uglify({
output: {
comments: (node, comment) => {
return comment.type === "comment2" && /html-dir-content v/i.test(comment.value);
}
}
}),
]
}),
])
.then(() => {
console.info(chalk.green(`✓✓✓ BUILD SUCCESS!`));
})
.catch((error) => {
console.error(chalk.magenta(`!!! BUILD - ERROR!!!!!`), error);
process.exit(1); //exit with error
});