-
Notifications
You must be signed in to change notification settings - Fork 18
/
rollup.config.mjs
54 lines (46 loc) · 1.4 KB
/
rollup.config.mjs
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
import fs from 'fs';
import banner from 'rollup-plugin-banner2';
import replace from '@rollup/plugin-replace';
import { string } from './build/strings-plugin.mjs';
import userScriptMetadataBlock from './build/metadata.mjs';
const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
let packageJson = loadJSON('./package.json');
const entry = 'src/index.js';
const config = [
// Modern Module (No babel preset)
{
input: entry,
output: [
{
file: packageJson.main,
format: 'iife',
// exports: 'default',
},
],
plugins: [
replace({
preventAssignment: true,
__VERSION__: JSON.stringify(packageJson.version),
__HOMEPAGE__: JSON.stringify(packageJson.homepage)
}),
banner(userScriptMetadataBlock),
// import html as string
string({
include: ['**/*.html'],
}),
// import css as string
string({
include: ['**/*.css'],
transform(code) {
return code
.replace(/;\s*\n\s*/g, '; ') // remove line breaks after ;
.replace(/\{\n */g, '{ ') // remove line break after {
.replace(/^\s*\n/gm, '') // remove empty lines
.replace(/;\s(\/\*.+\*\/)\n/g, '; $1 ') // remove line break after comments on properties
.trim();
}
}),
]
},
];
export default config;