-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
89 lines (79 loc) · 2.03 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
import { defineConfig } from 'rollup';
import alias from '@rollup/plugin-alias';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import styles from 'rollup-plugin-styles';
import { terser } from 'rollup-plugin-terser';
import { name } from './package.json';
import os from 'os';
import path from 'path';
function GetBetterDiscordPath() {
switch (os.platform()) {
case 'darwin':
return [process.env.HOME, 'Library/Application Support/BetterDiscord/plugins/'];
case 'win32':
return [process.env.HOME, 'AppData/Roaming/BetterDiscord/plugins/'];
default:
throw Error(
'Platform not implemented, please submit an issue at https://github.com/chazzox/plugin-template/issues or make a pr :)'
);
}
}
const meta = `
/**
* @name ExamplePlugin
* @author chazzox#1001
* @description BoilerPlate extension for anyone to use :)
* @version 0.0.1
* @website https://github.com/chazzox/plugin-template#readme
* @source https://github.com/chazzox/plugin-template
*/
`;
export default defineConfig({
input: `src/${name}.tsx`,
output: [
{
file: `plugin/${name}.plugin.js`,
format: 'cjs',
banner: meta
},
{
file: path.join(...GetBetterDiscordPath(), `${name}.plugin.js`),
format: 'cjs',
banner: meta
}
],
plugins: [
// fixing any node_module react import
alias({
entries: [{ find: 'react', replacement: path.resolve(path.resolve(__dirname), 'src/react.ts') }]
}),
// resolve imports
nodeResolve(),
commonjs(),
// .scss files to inline BdApi string
styles({
minimize: true,
extensions: ['.scss'],
mode: [
'inject',
(varname, id) => {
return `BdApi.injectCSS("${name}-styles",${varname})`;
}
]
}),
// jsx transformer
typescript(),
// minifier
terser({
module: true,
compress: { sequences: false },
mangle: {},
parse: {},
rename: {},
// Remove all comments *except* the meta comment at the top
format: { comments: '/@name/' }
})
]
});