This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
rollup.config.js
170 lines (150 loc) · 4.7 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* eslint-env node */
import path from 'path';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import { getPackages } from '@lerna/project';
import filterPackages from '@lerna/filter-packages';
import batchPackages from '@lerna/batch-packages';
async function getSortedPackages(scope, ignore)
{
const packages = await getPackages(__dirname);
const filtered = filterPackages(
packages,
scope,
ignore,
false,
);
return batchPackages(filtered)
.reduce((arr, batch) => arr.concat(batch), []);
}
async function main()
{
const plugins = [
sourcemaps(),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs({
namedExports: {
'resource-loader': ['Resource'],
},
}),
typescript(),
];
const external = ['pixi.js', '@pixi/filter-drop-shadow'];
const globals = {
'pixi.js': 'PIXI',
'@pixi/filter-drop-shadow': '__filters',
};
const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC');
const results = [];
const packages = await getSortedPackages();
packages.forEach((pkg) =>
{
let banner = [
`/*!`,
` * ${pkg.name} - v${pkg.version}`,
` * Compiled ${compiled}`,
` *`,
` * ${pkg.name} is licensed under the MIT License.`,
` * http://www.opensource.org/licenses/mit-license`,
` */`,
].join('\n');
const basePath = path.relative(__dirname, pkg.location);
const input = path.join(basePath, 'src/index.ts');
const {
main,
module,
bundle,
namespace,
} = pkg.toJSON();
results.push({
input,
output: [
{
banner: `${banner}\n// cjs`,
file: path.join(basePath, main),
format: 'cjs',
sourcemap: true,
freeze: false,
globals,
},
{
banner: `${banner}\n// mjs`,
file: path.join(basePath, module),
format: 'esm',
sourcemap: true,
freeze: false,
globals,
},
],
plugins,
external,
});
if (bundle)
{
const file = path.join(basePath, bundle);
const ns = namespace || 'PUXI';
const name = pkg.name.replace(/[^a-z]+/g, '_');
if (ns.includes('.'))
{
// Base namespace (PUXI)
const baseNs = ns.split('.')[0];
// this.PUXI = this.PUXI || {} - initialize PUXI if not yet
banner += `\nthis.${baseNs} = this.${baseNs} || {};`;
}
// this.PUXI.tween = this.PUXI.tween || {} - initialize ns if not yet
banner += `\nthis.${ns} = this.${ns} || {};`;
// Inject module into its namespace
const footer = `Object.assign(this.${ns}, ${name})`;
results.push({
input,
output: [
{
banner,
name,
file,
format: 'iife',
sourcemap: true,
globals,
footer,
},
],
treeshake: false,
plugins,
external,
});
if (process.env.NODE_ENV === 'production')
{
results.push({
input,
output: [{
banner,
name,
file: file.replace(/\.js$/, '.min.js'),
format: 'iife',
sourcemap: true,
globals,
footer,
}],
treeshake: false,
plugins: [
...plugins,
terser({
output: {
comments: (node, comment) => comment.line === 1,
},
}),
],
external,
});
}
}
});
return results;
}
export default main();