forked from maptalks/maptalks.three
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
174 lines (164 loc) · 4.42 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
171
172
173
174
import { DEFAULT_EXTENSIONS } from '@babel/core';
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
const pkg = require('./package.json');
const dev = process.env.BUILD === 'dev';
const banner = `/*!\n * ${pkg.name} v${pkg.version}\n * LICENSE : ${pkg.license}\n * (c) 2016-${new Date().getFullYear()} maptalks.org\n */`;
let outro = pkg.name + ' v' + pkg.version;
if (pkg.peerDependencies && pkg.peerDependencies['maptalks']) {
outro += `, requires maptalks@${pkg.peerDependencies.maptalks}.`;
}
outro = `typeof console !== 'undefined' && console.log('${outro}');`;
const intro = '';
function removeGlobal() {
return {
transform(code, id) {
if (id.indexOf('worker.js') === -1) return null;
const commonjsCode = /typeof global/g;
var transformedCode = code.replace(commonjsCode, 'typeof undefined');
return {
code: transformedCode,
map: { mappings: '' }
};
}
};
}
const basePlugins = [
json(),
typescript({
}),
//handle node_modules
resolve({
module: true,
jsnext: true,
main: true
}),
commonjs(),
//handle ES2015+
// babel({
// // exclude: 'node_modules/**'
// }),
removeGlobal()
];
const es5BasePlugins = [
json(),
typescript({
}),
//handle node_modules
resolve({
module: true,
jsnext: true,
main: true
}),
commonjs(),
//handle ES2015+
babel({
exclude: 'node_modules/**',
babelHelpers: 'bundled',
extensions: [
...DEFAULT_EXTENSIONS,
'.ts',
'.tsx'
]
}),
removeGlobal()
];
let bundleList = [
{
input: 'src/index.ts',
plugins: basePlugins,
external: ['maptalks', 'three'],
output: {
'sourcemap': true,
'format': 'umd',
'name': 'maptalks',
'banner': banner,
'outro': outro,
'extend': true,
'intro': intro,
'globals': {
'maptalks': 'maptalks',
'three': 'THREE'
},
'file': 'dist/maptalks.three.js'
}
},
{
input: 'src/index.ts',
plugins: basePlugins.concat([terser()]),
external: ['maptalks', 'three'],
output: {
'sourcemap': false,
'format': 'umd',
'name': 'maptalks',
'banner': banner,
'outro': outro,
'intro': intro,
'extend': true,
'globals': {
'maptalks': 'maptalks',
'three': 'THREE'
},
'file': 'dist/maptalks.three.min.js'
}
},
{
input: 'src/index.ts',
plugins: es5BasePlugins,
external: ['maptalks', 'three'],
output: {
'sourcemap': true,
'format': 'umd',
'name': 'maptalks',
'banner': banner,
'outro': outro,
'extend': true,
'intro': intro,
'globals': {
'maptalks': 'maptalks',
'three': 'THREE'
},
'file': 'dist/maptalks.three.es5.js'
}
},
{
input: 'src/index.ts',
plugins: es5BasePlugins.concat([terser()]),
external: ['maptalks', 'three'],
output: {
'sourcemap': false,
'format': 'umd',
'name': 'maptalks',
'banner': banner,
'outro': outro,
'intro': intro,
'extend': true,
'globals': {
'maptalks': 'maptalks',
'three': 'THREE'
},
'file': 'dist/maptalks.three.es5.min.js'
}
},
// {
// input: 'src/index.ts',
// plugins: basePlugins,
// external: ['maptalks', 'three'],
// output: {
// 'sourcemap': false,
// 'format': 'es',
// 'banner': banner,
// 'outro': outro,
// 'intro': intro,
// 'file': pkg.module
// }
// }
];
if (dev) {
bundleList = bundleList.slice(0, 1);
}
module.exports = bundleList;