-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
executable file
·351 lines (306 loc) · 9.2 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
This rollup performs all the build tasks required for all versions.
To execute, run the npm build command
npm run build
The results deploy to `build/` and `dist/` folders.
+ Each addon builds into a minified `dist/addons/name.js` (see addonsConfig)
## How does it work
The rollup tools expects configurations of assets. They're exported at the base
of this file. Each object contains an `input`str, `output`[] and `plugins`
export default [{
input: "path.js"
output: [
{file: 'dist/output.js', format: 'esm'},
{file: 'dist/output.js', format: 'umd', name: 'polything'},
]
, plugins: []
}]
Each stage does the following:
+ Use the created "merge" files within the `build/`
+ Create a minified `dist/` of each file discovered
*/
import resolve from '@rollup/plugin-node-resolve'; // Helps Rollup find external modules
import commonjs from '@rollup/plugin-commonjs'; // Converts CommonJS modules to ES6
import terser from '@rollup/plugin-terser'; // Minifies the bundle
// import ClassGraph from "./src/classgraph.js"
import concat from 'rollup-plugin-concat';
const ADDONS = [
"./src/addons/events.js"
, "./src/addons/font-pack.js"
, "./src/addons/monitor.js"
, "./src/addons/vars-box.js"
, "./src/addons/var-translate.js"
, "./src/addons/value-reduce.js"
]
const CORE = [
"./src/tools.js"
, "./src/dcss.js"
, "./src/classgraph.js"
]
const POLYCLASS = [
...CORE
, "./src/polyclass.js"
, "./src/export-statements.js"
]
const POLYCLASS_BROWSER = [
...CORE
, "./src/dom-property-activator.js"
, "./src/polyclass.js"
]
const groupedFiles = {
core: {
files: POLYCLASS
// files: CORE.concat(POLYCLASS)
, outputFile: './build/polyclass.core.js'
}
, addons: {
files: ADDONS
, outputFile: './build/addons.all.js'
}
, full: {
files: POLYCLASS.concat(ADDONS)
, outputFile: './build/polyclass.full.js'
}
// The browser requires the DOM loader and no ESM export.
, browser: {
files: POLYCLASS_BROWSER
, outputFile: './build/polyclass.browser-core.js'
}
, browserFull: {
files: POLYCLASS_BROWSER.concat(ADDONS)
, outputFile: './build/polyclass.browser-full.js'
}
}
const groupedFileOutputs = function(){
let res = []
for(let obj of Object.values(groupedFiles)){
res.push(obj.outputFile)
}
return res;
}
const coreConfig = {
input: groupedFiles.core.outputFile
, output: [
{
file: 'dist/core/esm/polyclass-core.js'
, format: 'esm'
}, {
file: 'dist/core/umd/polyclass-core.js'
, format: 'umd'
, name: 'polybundle'
}, {
file: 'dist/core/cjs/polyclass-core.cjs'
, format: 'cjs'
, name: 'polybundle'
}
]
, plugins: [
concat({
groupedFiles: Object.values(groupedFiles)
})
// Resolve external modules from node_modules
// resolve(),
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
// commonjs(),
// Minify the output
// terser()
]
}
const coreConfigMin = {
input: groupedFiles.core.outputFile
, output: [
{
file: 'dist/core/esm/polyclass-core.min.js'
, format: 'esm'
}, {
file: 'dist/core/umd/polyclass-core.min.js'
, format: 'umd'
, name: 'polybundle'
}, {
file: 'dist/core/cjs/polyclass-core.min.cjs'
, format: 'cjs'
, name: 'polybundle'
}
]
, plugins: [
// concat({
// groupedFiles: Object.values(groupedFiles)
// })
// Resolve external modules from node_modules
// resolve(),
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
// commonjs(),
// Minify the output
terser()
]
}
const coreConfigBrowser = {
input: groupedFiles.browser.outputFile
, output: [
{
file: 'dist/browser/esm/polyclass-core.js'
, format: 'esm'
}, {
file: 'dist/browser/umd/polyclass-core.js'
, format: 'umd'
, name: 'polybundle'
}, {
file: 'dist/browser/cjs/polyclass-core.cjs'
, format: 'cjs'
, name: 'polybundle'
}
]
, plugins: [
// concat({
// groupedFiles: Object.values(groupedFiles)
// })
// Resolve external modules from node_modules
// resolve(),
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
// commonjs(),
// Minify the output
// terser()
]
}
const coreConfigBrowserMin = {
input: groupedFiles.browser.outputFile
, output: [
{
file: 'dist/browser/esm/polyclass-core.min.js'
, format: 'esm'
}, {
file: 'dist/browser/umd/polyclass-core.min.js'
, format: 'umd'
, name: 'polybundle'
}, {
file: 'dist/browser/cjs/polyclass-core.min.cjs'
, format: 'cjs'
, name: 'polybundle'
}
]
, plugins: [
// concat({
// groupedFiles: Object.values(groupedFiles)
// })
// Resolve external modules from node_modules
// resolve(),
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
// commonjs(),
// Minify the output
terser()
]
}
/* All files created during the concat stage, with the merge files
within the `build/`.
Create a minified `dist/` of each file discovered.
*/
const buildFilesConfig = {
input: [
// "./src/module.js"
// , ...CORE
// , ...ADDONS
// , ...POLYCLASS
/* Created during the `concat` phase. */
...groupedFileOutputs()
]
, output: [{
dir: 'dist/', // Output file
// file: 'dist/polyclass-browser.js', // Output file
name: 'polyclass', // Global variable name when included directly in the browser
sourcemap: false, // Optional: generates a source map
format: 'esm'
}]
, plugins: [
// concat({
// groupedFiles: Object.values(groupedFiles)
// }),
// Resolve external modules from node_modules
resolve(),
// Minify the output
terser(),
]
}
// "output.format" - Valid values are "amd", "cjs", "system", "es", "iife" or "umd".
const polyclassFullConfig = {
input: groupedFiles.full.outputFile
, output: [
{
file: 'dist/full/esm/polyclass-full.js'
, format: 'esm'
}, {
file: 'dist/full/umd/polyclass-full.js'
, format: 'umd'
, name: 'polybundle'
}, {
file: 'dist/full/cjs/polyclass-full.cjs'
, format: 'cjs'
, name: 'polybundle'
}
]
, plugins: [
// Resolve external modules from node_modules
// resolve(),
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
// commonjs(),
// Minify the output
// , terser()
]
}
const polyclassFullConfigMin = {
input: groupedFiles.full.outputFile
, output: [
{
file: 'dist/full/esm/polyclass-full.min.js'
, format: 'esm'
}, {
file: 'dist/full/umd/polyclass-full.min.js'
, format: 'umd'
, name: 'polybundle'
}, {
file: 'dist/full/cjs/polyclass-full.min.cjs'
, format: 'cjs'
, name: 'polybundle'
}
]
, plugins: [
// Resolve external modules from node_modules
// resolve(),
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
// commonjs(),
// Minify the output
terser()
]
}
/* Create a minified `dist/addon` of each file within the ADDONS list.
*/
const addonsConfig = {
input: [
// "./src/module.js"
// , ...CORE
...ADDONS
// , ...POLYCLASS
]
, output: {
dir: 'dist/addons/', // Output file
// file: 'dist/polyclass-browser.js', // Output file
// format: 'iife', // Output format
name: 'polyclass', // Global variable name when included directly in the browser
sourcemap: false, // Optional: generates a source map
// inlineDynamicImports: true
}
, plugins: [
// Minify the output
terser()
]
}
// https://rollupjs.org/command-line-interface/#configuration-files
export default [
coreConfig
, coreConfigMin
, coreConfigBrowser
, coreConfigBrowserMin
, buildFilesConfig
, polyclassFullConfig
, polyclassFullConfigMin
, addonsConfig
]