-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
55 lines (49 loc) · 1.64 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
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import html from 'rollup-plugin-html';
import pkg from './package.json';
function wrap_in_iife() {
const [banner, footer] = (() => {
(function iife(inject) {
// Trick to get around the sandbox restrictions in Greasemonkey (Firefox)
// Inject code into the main window if criteria match
if (typeof GM_info === "object" && GM_info.scriptHandler === "Greasemonkey" && inject) {
window.eval("(" + iife.toString() + ")();");
return;
}
/* == INJECTION == */
})(true);
}).toString().slice(7, -1).split('/* == INJECTION == */');
return {
name: 'wrap_in_iife',
banner,
footer,
};
}
function add_header_file(path, transform) {
const fileContent = readFileSync(path, 'utf8');
return {
name: "add_header_file",
banner: transform ? transform(fileContent) : fileContent
}
}
function set_script_version(meta) {
return meta.replace('%version%', pkg.version);
}
export default {
input: 'src/main.js',
output: {
file: 'dist/Simple-YouTube-Age-Restriction-Bypass.user.js',
format: 'esm',
},
plugins: [
html(),
nodeResolve(),
add_header_file(resolve(__dirname, 'userscript.config.js'), set_script_version),
// Manually wrap code in our custom iife
wrap_in_iife(),
getBabelOutputPlugin({ configFile: resolve(__dirname, 'babel.config.js') }),
],
};