-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
90 lines (82 loc) · 2.26 KB
/
rollup.config.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
/* eslint-disable no-console */
const rollup = require("rollup");
const rollupTypescript = require("rollup-plugin-typescript2");
const { uglify } = require("rollup-plugin-uglify");
const { resolve } = require("path");
const nodeResolve = require("rollup-plugin-node-resolve");
const pwd = (...args) => resolve(process.cwd(), ...args);
const fs = require("fs-extra");
const argv = process.argv.splice(2);
const tsconfig = require("./tsconfig.json");
function clearDir(dir) {
if (fs.existsSync(dir)) {
const files = fs.readdirSync(dir);
files.forEach((file) => {
fs.remove(`$\{dir}/file`);
});
}
}
function haveArgv(...args) {
let isHave = false;
args.forEach((str) => {
argv.forEach((v) => {
if (v === str) {
isHave = true;
}
});
});
return isHave;
}
clearDir(pwd("umd"));
// fs.copySync("./example/src/lib", "./lib");
const watchOptions = [
{
input: "./lib/index.ts",
output: {
file: "./umd/index.js",
format: "umd",
name: "$verk",
sourcemap: false,
},
plugins: [
nodeResolve(),
rollupTypescript({
useTsconfigDeclarationDir: false,
}),
// uglify({
// mangle: {
// eval: true,
// },
// sourcemap: false,
// }),
],
},
];
const watcher = rollup.watch(watchOptions);
// event.code can be one of:
// START — the watcher is (re)starting
// BUNDLE_START — building an individual bundle
// BUNDLE_END — finished building a bundle
// END — finished building all bundles
// ERROR — encountered an error while bundling
// FATAL — encountered an unrecoverable error
watcher.on("event", (event) => {
if (event.code === "ERROR") {
console.log(event);
} else if (event.code === "BUNDLE_END") {
// console.log(event);
console.log("BUNDLE_END");
} else if (event.code === "END") {
if (!haveArgv("--watch", "-w")) {
watcher.close();
}
// fs.copySync("./example/src/lib", "./lib");
fs.copySync("./umd/index.js", "./webside/js/verk.js");
// fs.copySync(
// "./umd/index.js",
// "/Users/pillar/work/github/tinyci/static/js/verk.js"
// );
// fs.copySync("./dev/bindcss.js", "./webside/verk/bindcss.js");
}
});