-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
83 lines (76 loc) · 2.25 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
/* eslint-disable unicorn/no-nested-ternary */
import { format } from "date-fns";
import { readFileSync } from "fs";
import { sync as globby } from "globby";
import babel from "rollup-plugin-babel";
import prettier from "rollup-plugin-prettier";
import sourcemaps from "rollup-plugin-sourcemaps";
import { uglify } from "rollup-plugin-uglify";
const getBuildDate = () => format(new Date(), "dd MMMM yyyy");
const pkg = require("./package.json");
const getActualBanner = () => {
const licenseText = readFileSync("./LICENSE", "utf-8");
const banner = `/**
* ${pkg.name}
* ${pkg.description}
*
* @author ${pkg.author.name} <${pkg.author.email}>
* @version v${pkg.version}
* @link ${pkg.homepage}
* @date ${getBuildDate()}
*
${licenseText.replace(/^/gm, " * ")}
*/
`;
return banner;
};
const getSourceFilesList = () => globby(["src/*.js"]);
const getMainFileAsList = () => globby(["src/index.js"]);
const getFileName = file =>
file
.split("/")
.pop()
.split(".")
.slice(0, -1)
.join(".");
const getOutput = (input, extension) => `${getFileName(input)}.${extension}`;
const getUmdFileName = file => {
const fileName = getFileName(file);
if (fileName === "index") {
return "fun-ctional";
}
return fileName;
};
const getUmdOutput = (input, minified = false) => `${getUmdFileName(input)}${minified ? ".min" : ""}.js`;
const config = (format, folder, minified = false) => input => ({
input,
output: {
file: `${folder ? folder + "/" : ""}${
format === "umd" ? getUmdOutput(input, minified) : getOutput(input, "js")
}`,
format,
sourcemap: true,
sourcemapFile: `${folder ? folder + "/" : ""}${getOutput(input, "js")}.map`,
strict: true,
banner: getActualBanner(),
name: format === "umd" ? "funCtional" : undefined
},
plugins:
format === "umd"
? minified
? [babel(), uglify(), sourcemaps()]
: process.env.CI
? [babel(), sourcemaps()]
: [babel(), prettier(), sourcemaps()]
: process.env.CI
? [sourcemaps()]
: [prettier(), sourcemaps()]
});
const sourceFiles = getSourceFilesList();
const mainFileAsList = getMainFileAsList();
export default [
...sourceFiles.map(config("cjs")),
...mainFileAsList.map(config("es", "esm")),
...sourceFiles.map(config("umd", "browser")),
...sourceFiles.map(config("umd", "browser", true))
];