-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
50 lines (43 loc) · 1.53 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
import { format } from "date-fns";
import { readFileSync } from "fs";
import { sync as globby } from "globby";
import resolve from "rollup-plugin-node-resolve";
import prettier from "rollup-plugin-prettier";
import sourcemaps from "rollup-plugin-sourcemaps";
const getBuildDate = () => format(new Date(), "dd MMMM yyyy");
const packageJson = require("./package.json");
const getActualBanner = () => {
const licenseText = readFileSync("./LICENSE", "utf-8");
const banner = `/**
* ${packageJson.name}
* ${packageJson.description}
*
* @author ${packageJson.author.name} <${packageJson.author.email}>
* @version v${packageJson.version}
* @link ${packageJson.homepage}
* @date ${getBuildDate()}
*
${licenseText.replace(/^/gm, " * ")}
*/
`;
return banner;
};
const getSourceFilesList = () => globby(["src/*.js"]);
const getFileName = file => file.split("/").pop().split(".").slice(0, -1).join(".");
const getOutput = (input, extension) => `${getFileName(input)}.${extension}`;
const getFolderPart = folder => (folder ? folder + "/" : "");
const config = (format, folder) => input => ({
input,
output: {
file: `${getFolderPart(folder)}${getOutput(input, "js")}`,
format,
sourcemap: true,
sourcemapFile: `${getFolderPart(folder)}${getOutput(input, "js")}.map`,
strict: true,
banner: getActualBanner()
},
external: ["path", "fs", "util"],
plugins: [resolve(), prettier(), sourcemaps()]
});
const sourceFiles = getSourceFilesList();
export default [...sourceFiles.map(config("cjs", "dist")), ...sourceFiles.map(config("es", "esm"))];