forked from mayflower-tech/react-pixi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
92 lines (84 loc) · 2.63 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
import commonjs from 'rollup-plugin-commonjs'
import filesize from 'rollup-plugin-filesize'
import resolve from 'rollup-plugin-node-resolve'
import { terser } from 'rollup-plugin-terser'
import json from 'rollup-plugin-json'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import globals from 'rollup-plugin-node-globals'
import alias from '@rollup/plugin-alias'
const prod = process.env.NODE_ENV === 'production'
const format = process.env.FORMAT
function getConfig(dest, format, merge = {}) {
return {
input: merge.input || 'src/index.js',
output: {
exports: 'named',
file: dest,
format,
name: 'ReactPixi',
sourcemap: !prod,
globals: {
'pixi.js': 'PIXI',
'pixi.js-legacy': 'PIXI',
react: 'React',
},
...(merge.output || {}),
},
plugins: [
json(),
babel({ exclude: 'node_modules/**' }),
...(merge.beforePlugins || []),
resolve({
browser: true,
mainFields: ['main', 'jsnext'],
}),
commonjs({
ignoreGlobal: false,
namedExports: {
'node_modules/scheduler/index.js': ['unstable_scheduleCallback', 'unstable_cancelCallback'],
'@react-spring/animated': ["createHost"]
},
}),
replace({
__DEV__: prod ? 'false' : 'true',
'process.env.NODE_ENV': prod ? '"production"' : '"development"',
}),
globals(),
...(merge.afterPlugins || []),
prod && terser(),
filesize(),
].filter(Boolean),
external: ['pixi.js', 'pixi.js-legacy', 'react', 'react-dom'],
}
}
const buildType = prod ? '' : '-dev'
let builds = []
if (format) {
builds.push(
getConfig(`dist/react-pixi.${format}${buildType}.js`, format, {
beforePlugins: [alias({ entries: { '@react-spring/animated': './react-spring-create-host.js' } })],
})
)
} else {
;['cjs', 'umd', 'es'].forEach(format => {
builds.push(
// default
getConfig(`dist/react-pixi.${format}${buildType}.js`, format, {
beforePlugins: [alias({ entries: { '@react-spring/animated': './react-spring-create-host.js' } })],
}),
// animated
getConfig(`animated/react-pixi.${format}${buildType}.js`, format, { input: 'src/index-animated.js' }),
// pixi legacy
getConfig(`legacy/react-pixi.${format}${buildType}.js`, format, {
beforePlugins: [
alias({ entries: { '@react-spring/animated': './react-spring-create-host.js' } }),
babel({
plugins: [['module-resolver', { alias: { 'pixi.js': 'pixi.js-legacy' } }]],
}),
],
})
)
})
}
export default builds