-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
141 lines (120 loc) · 3.16 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import path from 'path';
import fs from 'fs';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import esbuild from 'rollup-plugin-esbuild';
import { dts } from "rollup-plugin-dts";
import repo from "./package.json" assert { type: 'json' };
const isProduction = process.env.NODE_ENV === 'production';
const esbuildConfig = {
target: 'es2020',
minifySyntax: true,
define: {
'process.env.VERSION': `'${repo.version}'`,
'process.env.DEBUG': isProduction?'false':'true',
},
treeShaking: true,
minify: isProduction,
tsconfigRaw: '{"compilerOptions":{"useDefineForClassFields":false}}'
}
const plugins = [
esbuild(esbuildConfig),
resolve({
browser: true,
preferBuiltins: false,
}),
json(),
commonjs(),
];
const sourcemap = true;//!isProduction;
const freeze=false;
const compiled = (new Date()).toUTCString().replace(/GMT/g, "UTC");
const banner = `/*!
* ${repo.name} - v${repo.version}
* By Hocti
* Compiled ${compiled}
*
* ${repo.name} is licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license
*/`;
function prodName(name)
{
return name.replace(/\.(m)?js$/, '.min.$1js');
}
const globals={
/*
'pixi.js':'PIXI',
'@pixi/core': 'PIXI',
'@pixi/constants': 'PIXI',
'@pixi/settings': 'PIXI',
'@pixi/math': 'PIXI',
'@pixi/sprite': 'PIXI',
'@pixi/ticker': 'PIXI',
'@pixi/display': 'PIXI',
'@pixi/loaders': 'PIXI',
'@pixi/assets': 'PIXI',
'@pixi/utils': 'PIXI.utils',
'@pixi/filter-blur':'PIXI',
'@pixi/filter-color-matrix':'PIXI',
'eventemitter3':'eventemitter3',
*/
'pixi.js':'PIXI',
'@pixi/sound':'PIXI.sound',
'pixi-filters':'PIXI.filters'
}
async function main() {
const results=[];
results.push(
{
input: "src/index.ts",
external: Object.keys(repo.peerDependencies),
output: [
{
name: repo.namespace,
banner,
freeze,
sourcemap,
format: "iife",
file: repo.bundle,
globals
},
{
banner,
freeze,
sourcemap,
format: "esm",
file: repo.module,
globals
},
{
banner,
freeze,
sourcemap,
format: "cjs",
file: repo.main,
globals
}
],
plugins
});
if(isProduction){
results.push(
{
input: "src/index.ts",
external: Object.keys(repo.peerDependencies),
output: [
{
banner:banner,
file: repo.types,
format: "es",
globals
}
],
plugins:[dts()],
});
}
return results;
}
export default main();