forked from victornpb/undiscord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
executable file
·118 lines (105 loc) · 3.21 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
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
import fs from 'fs';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import banner from 'rollup-plugin-banner2';
import json from '@rollup/plugin-json';
import serve from 'rollup-plugin-serve';
import bakedEnv from 'rollup-plugin-baked-env';
import S from 'tiny-dedent';
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');
process.env.VERSION = packageJson.version;
const production = !process.env.ROLLUP_WATCH;
const sourcemap = production ? false : 'inline';
const entry = 'src/index.js';
// const assumptions = {
// constantSuper: true,
// enumerableModuleMeta: true,
// ignoreFunctionLength: true,
// ignoreToPrimitiveHint: true,
// noClassCalls: true,
// noDocumentAll: true,
// noNewArrows: true,
// privateFieldsAsProperties: true,
// setClassMethods: true,
// setComputedProperties: true,
// setPublicClassFields: true,
// };
let devPlugins = [];
if (!production) {
devPlugins = [
{
buildStart() {
packageJson = loadJSON('./package.json');
const DEV_VERSION = `0.${new Date().toISOString().replace(/[-:T]/g, '.').replace('Z', '')}-dev`;
process.env.VERSION = DEV_VERSION;
}
},
serve({
// Launch in browser (default: false)
// open: true,
openPage: '/' + packageJson.main,
// contentBase: 'dist'
host: 'localhost',
port: 10001,
headers: {
'Access-Control-Allow-Origin': '*',
},
onListening(server) {
const address = server.address();
const host = address.address === '::1' ? 'localhost' : address.address;
// by using a bound function, we can access options as `this`
const protocol = this.https ? 'https' : 'http';
console.log(S(`
\n\n
Live server started...
_____________________________________________________________
👇 Open this URL to install the development user extension 👇
${protocol}://${host}:${address.port}/${packageJson.main}
_____________________________________________________________
`));
}
}),
];
}
const config = [
// Modern Module (No babel preset)
{
input: entry,
output: [
{
file: packageJson.main,
format: 'iife',
sourcemap,
// exports: 'default',
},
],
plugins: [
...devPlugins,
bakedEnv(),
json(),
resolve(),
commonjs(),
banner(userScriptMetadataBlock),
// import html as string
string({
include: ['**/*.html'],
}),
// import css as string
string({
include: ['**/*.css'],
transform(code, id) {
// compact CSS
return code
.replace(/^\s*\n/gm, '') // remove empty lines
.replace(/\{\n */g, '{ ') // remove line break after {
.replace(/;\n */g, '; ') // remove line breaks after ;
.replace(/;\s(\/\*.+\*\/)\n/g,'; $1 '); // remove line break after comments on properties
}
}),
]
},
];
export default config;