generated from Alorel/basic-library-template-repo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
156 lines (149 loc) · 3.41 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import {copyPlugin} from "@alorel/rollup-plugin-copy";
import modWrapPlugin from "./build/mod-wrap.mjs";
import replacePlugin from "@rollup/plugin-replace";
import iifeWrapPlugin from "./build/iife-wrap.mjs";
import {threadedTerserPlugin} from "@alorel/rollup-plugin-threaded-terser";
import {assetLoader} from "./build/asset-loader.mjs";
import jsonPlugin from "@rollup/plugin-json";
import cleanPlugin from "./build/clean-plugin.mjs";
import scssLoader from "./build/scss-loader.mjs";
import loadFirstPlugin from "./build/load-first.mjs";
const srcInclude = /src[\\/].+\.m?tsx?$/;
const srcExclude = /node_modules[\\/]/;
export default function (opts) {
const watch = opts.watch;
const prod = Boolean(getOpt(opts, 'prod'));
return {
input: 'src/setup.tsx',
output: {
dir: 'dist',
format: 'es',
generatedCode: {
arrowFunctions: true,
constBindings: true,
objectShorthand: true,
},
preserveModules: false,
sourcemap: false,
entryFileNames: 'setup.mjs',
},
plugins: [
cleanPlugin(),
mkNodeResolve(),
jsonPlugin({
compact: true,
include: '**/*.json',
namedExports: true,
preferConst: true,
}),
scssLoader({prod}),
typescript({exclude: srcExclude, include: srcInclude}),
!prod && loadFirstPlugin(),
replacePlugin({
exclude: srcExclude,
include: srcInclude,
preventAssignment: true,
values: {
'process.env.MELVOR_MOD_VERSION': JSON.stringify(process.env.MELVOR_MOD_VERSION || 'dev'),
'process.env.PRODUCTION': String(prod),
},
}),
assetLoader({
reg: /\.png$/,
}),
prod && mkIifeWrap(),
modWrapPlugin({prod}),
prod && threadedTerserPlugin({
terserOpts: {
output: {
comments: false,
},
},
}),
copyPlugin({
copy: [
{
from: [
'manifest.json',
// 'public_api.d.ts',
],
opts: {glob: {cwd: 'src'}}
},
{from: 'LICENSE'},
],
defaultOpts: {
emitNameKind: 'fileName',
},
watch,
}),
],
watch: {
exclude: 'node_modules/**/*',
},
};
}
function getOpt(opts, opt) {
if (opt in opts) {
const out = opts[opt];
delete opts[opt];
return out;
}
}
function mkIifeWrap() {
return iifeWrapPlugin({
async: true,
vars: [
'AltMagicConsumptionID',
'Array',
'AttackTypeID',
'Bank',
'Boolean',
'cdnMedia',
'CombatManager',
'console',
'document',
'Equipment',
'EquippedFood',
'Error',
'game',
'isNaN',
'JSON',
'Map',
'NamespacedObject',
'NamespaceRegistry',
'Number',
'Object',
'Player',
'Promise',
'RegExp',
'sidebar',
'SkillWithMastery',
'String',
'Symbol',
'Swal',
'TypeError',
'undefined',
'WeakMap',
'window',
],
});
}
function mkNodeResolve() {
return nodeResolve({
exportConditions: [
'es2015',
'module',
'import',
'default',
],
mainFields: [
'es2015',
'esm2015',
'module',
'browser',
'main',
],
});
}