-
Notifications
You must be signed in to change notification settings - Fork 142
/
rollup.config.js
75 lines (67 loc) · 1.8 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
/* eslint-env node */
import commonjs from '@rollup/plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import transformTaggedTemplate from 'rollup-plugin-transform-tagged-template';
import typescript from '@rollup/plugin-typescript';
import {terser} from 'rollup-plugin-terser';
import del from 'rollup-plugin-delete';
// ----- Rollup Config -----
const parserOptions = {
sourceType: 'module',
};
export default [
{
context: 'this',
input: 'src/index-rollup.ts',
output: [
{
file: 'dist/toolkit.js',
format: 'esm',
},
{
file: 'dist/toolkit.min.js',
format: 'esm',
plugins: [terser()],
},
],
plugins: [
del({targets: 'dist/*'}),
nodeResolve(),
commonjs(),
typescript(),
transformTaggedTemplate({
tagsToProcess: ['css'],
transformer: transformCSSFragment,
parserOptions,
}),
transformTaggedTemplate({
tagsToProcess: ['html'],
transformer: transformHTMLFragment,
parserOptions,
}),
filesize({
showMinifiedSize: false,
showBrotliSize: true,
}),
],
},
];
// ----- Helper Functions -----
function transformHTMLFragment(data) {
const spaceBeforeAfterAngleBrackets = /\s*([<>])\s*/g; // remove spaces before and after angle brackets
data = data.replace(spaceBeforeAfterAngleBrackets, '$1');
return data.replace(/\s{2,}/g, ' '); // Collapse all sequences to 1 space
}
function transformCSSFragment(data) {
const newlines = /\n/g;
const separators = /\s*([{};])\s*/g;
const lastProp = /;\s*(\})/g;
const extraSpaces = /\s\s+/g;
const endingSpaces = / ?\s+$/g;
data = data.replace(newlines, '');
data = data.replace(separators, '$1');
data = data.replace(lastProp, '$1');
data = data.replace(endingSpaces, ' ');
return data.replace(extraSpaces, ' ');
}