-
Notifications
You must be signed in to change notification settings - Fork 18
/
rollup.config.mjs
132 lines (119 loc) · 3.46 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
// rollup.config.mjs
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import alias from '@rollup/plugin-alias';
import { babel } from '@rollup/plugin-babel';
/** @typedef {import('rollup').RollupOptions} RollupOptions */
/** @typedef {import('rollup').Plugin} Plugin */
/** @typedef {import('rollup').OutputOptions} OutputOptions */
/** @typedef {import('@rollup/plugin-babel').RollupBabelInputPluginOptions} RollupBabelInputPluginOptions */
const banner = `/* Copyright 2015-${new Date().getFullYear()} PlayCanvas Ltd */\n`;
/**
* @example
* {
* name: 'playcanvas-spine.4.0',
* lib: 'spine40' // replacement for import alias
* }
*/
const builds = [
{
name: 'playcanvas-spine.3.6',
lib: 'contrib/spine-ts/build/3.6/spine-core.js'
},
{
name: 'playcanvas-spine.3.8',
lib: 'contrib/spine-ts/build/3.8/spine-core.js'
},
{
name: 'playcanvas-spine.4.0',
lib: 'src/wrapper40.js'
},
{
name: 'playcanvas-spine.4.1',
lib: 'src/wrapper41.js'
},
{
name: 'playcanvas-spine.4.2',
lib: 'src/wrapper42.js'
}
];
/**
* The ES5 options for babel(...) plugin.
*
* @param {'debug'|'release'|'profiler'|'min'} buildType - Use 'debug' for comments
* @returns {RollupBabelInputPluginOptions} The babel options.
*/
const es5Options = buildType => ({
babelHelpers: 'bundled',
babelrc: false,
comments: buildType === 'debug',
compact: false,
minified: false,
presets: [
[
'@babel/preset-env', {
modules: false,
targets: {
ie: '11'
}
}
]
]
});
/**
* Return all the build targets.
*
* @returns {RollupOptions | RollupOptions[]} Build targets.
*/
export default [
...builds.map(buildDefinition => buildTarget(buildDefinition))
];
/**
* Return a target that rollup is supposed to build.
*
* @param {{ name, lib }} buildDefinition - The build definition.
* @returns {RollupOptions} One rollup target.
*/
function buildTarget({ name, lib }) {
const outputDir = './build/';
const outputPlugins = {
release: [],
min: [terser()]
};
const outputGlobals = {
playcanvas: 'pc'
};
// spine-core-import is an alias
const entries = { 'spine-core-import': lib };
const buildPlugins = [alias({ entries }), commonjs(), nodeResolve(), babel(es5Options('release'))];
return {
external: ['playcanvas'],
input: 'src/SpinePlugin.js',
context: 'this', // remove when using ESM libs
output: [
{
file: `${outputDir + name}.js`,
format: 'iife',
name: 'spine',
banner: banner,
indent: '\t',
preserveModules: false,
globals: outputGlobals,
generatedCode: 'es5', // refers to rollup wrappers
plugins: outputPlugins.release
},
{
file: `${outputDir + name}.min.js`,
format: 'iife',
name: 'spine',
banner: banner,
preserveModules: false,
globals: outputGlobals,
generatedCode: 'es5', // refers to rollup wrappers
plugins: outputPlugins.min
}
],
plugins: buildPlugins
};
}