-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
155 lines (148 loc) · 3.99 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import pkg from "./package.json";
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";
import svelte from "rollup-plugin-svelte";
import html from "@rollup/plugin-html";
import cleaner from "rollup-plugin-cleaner";
import { preserveShebangs } from "rollup-plugin-preserve-shebangs";
import replace from "@rollup/plugin-replace";
const production = !process.env.ROLLUP_WATCH;
export default [
// UMD
{
input: "src/index.ts",
output: {
name: "evalNumExpr",
file: pkg.browser,
format: "umd",
},
plugins: [typescript({ sourceMap: false })],
},
// CommonJS (for Node) and ES module (for bundlers) build.
{
input: "src/index.ts",
output: [
{ file: pkg.main, format: "cjs", exports: "auto" },
{ file: pkg.module, format: "es" },
],
plugins: [typescript({ sourceMap: false })],
},
// CLI CommonJS (for Node)
{
input: "cli/index.ts",
output: {
name: "evalNumExpr",
file: pkg.bin["evalNumExpr"],
format: "cjs",
},
plugins: [preserveShebangs(), typescript({ sourceMap: false })],
},
// docs
{
input: "docs/main.js",
output: {
file: ".out/main.js",
format: "iife", // immediately-invoked function expression — suitable for <script> tags
sourcemap: true,
},
plugins: [
cleaner({
targets: [".out"],
}),
resolve(), // tells Rollup how to find date-fns in node_modules
commonjs(), // converts date-fns to ES modules
svelte({
emitCss: false,
}), // handle svelte
typescript({ sourceMap: true }),
production && terser(), // minify, but only in production
replace({
APP_VERSION: process.env.npm_package_version,
preventAssignment: true,
}),
html({
filename: "index.html",
title: "Evaluate Numeric Expressions",
template: function ({ files, attributes, title, meta, publicPath }) {
const scripts = (files.js || [])
.map(({ fileName }) => {
const attrs = makeHtmlAttributes(attributes.script);
return `<script src="${publicPath}${fileName}"${attrs}></script>`;
})
.join("\n");
const links = (files.css || [])
.map(({ fileName }) => {
const attrs = makeHtmlAttributes(attributes.link);
return `<link href="${publicPath}${fileName}" rel="stylesheet"${attrs}>`;
})
.join("\n");
const metas = meta
.map((input) => {
const attrs = makeHtmlAttributes(input);
return `<meta${attrs}>`;
})
.join("\n");
return `<!DOCTYPE html>
<html ${attributes}>
<head>
${metas}
<title>${title}</title>
${links}
<style>
@import url("https://fonts.googleapis.com/css?family=Lato:400");
html {
font-size: 16px;
height: 100%;
}
@media all and (max-width: 959px) and (min-width: 600px) {
html {
font-size: 15px;
}
}
@media all and (max-width: 599px) and (min-width: 320px) {
html {
font-size: 13px;
}
}
html,
body {
height: 100%;
min-height: 100%;
}
* {
box-sizing: border-box;
}
body {
font-family: "Lato", sans-serif;
line-height: 1.6;
font-weight: 400;
margin: 0;
min-height: 100%;
background: white;
margin: 0;
}
</style>
</head>
<body>
<div id="root" />
${scripts}
</body>
</html>`;
},
}),
],
},
];
export const makeHtmlAttributes = (attributes) => {
if (!attributes) {
return "";
}
const keys = Object.keys(attributes);
// eslint-disable-next-line no-param-reassign
return keys.reduce(
(result, key) => (result += ` ${key}="${attributes[key]}"`),
""
);
};