This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
forked from GooseMod/GooseMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
103 lines (78 loc) · 2.23 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
import { resolve } from 'path';
import { readdirSync } from 'fs';
// Rollup plugins
import localResolve from 'rollup-plugin-local-resolve';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import serve from 'rollup-plugin-serve';
// PostCSS plugins
import pcImport from 'postcss-import';
// Custom plugins
import goosemod from './building/rollup-plugin-gm/index';
const goosemodBootstrap = () => ({
name: 'goosemod-bootstrap',
renderChunk: async (code) => code.replaceAll('<buildtime>', Date.now())
});
const ignoreEvalWarnings = (warning, warn) => {
if (warning.code === 'EVAL') return; // Suppress eval warnings
warn(warning);
};
const prod = !process.env.ROLLUP_WATCH;
export default [
{
input: './src/index.js',
output: {
file: './dist/goosemod.js',
format: 'iife',
name: 'goosemod',
sourcemap: !prod,
freeze: false // Do not freeze exports
},
plugins: [
localResolve(),
prod && terser(),
!prod && serve({
contentBase: 'dist',
port: 1234,
headers: {
'Access-Control-Allow-Origin': '*',
}
}),
postcss({
minimize: prod,
sourceMap: !prod,
plugins: [
pcImport({
resolve: (id, base, opts) => { // Resolve for @import
if (id.endsWith('/')) { // Directory resolving, eg: test/ imports all css files in test dir
const dir = resolve(base, id);
return readdirSync(dir).filter((x) => x.split('.').pop().startsWith('css')).map((x) => resolve(dir, x));
}
return resolve(base, id);
},
})
]
}),
goosemod()
],
onwarn: ignoreEvalWarnings,
inlineDynamicImports: true // Fix rollup jank
},
{
input: './bootstrap/index.js',
output: {
file: './dist/index.js',
format: 'iife',
name: 'goosemod_bootstrap',
sourcemap: !prod,
freeze: false // Do not freeze exports
},
plugins: [
localResolve(),
prod && terser(),
goosemodBootstrap()
],
onwarn: ignoreEvalWarnings,
inlineDynamicImports: true // Fix rollup jank
}
];