-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrollup.config.js
106 lines (100 loc) · 3.21 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
const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const terser = require('rollup-plugin-terser').terser;
const pkg = require('./package.json');
const production = process.env.BUILD === 'production';
const outputFile = production ? 'dist/maptalks.heatmap.js' : 'dist/maptalks.heatmap.js';
const outputESFile = 'dist/maptalks.heatmap.es.js'
const plugins = [
].concat(production ? [
removeGlobal(),
terser({
output : {
keep_quoted_props: true,
beautify: false,
comments : '/^!/'
}
})
] : []);
//worker.js中的global可能被webpack替换为全局变量,造成worker代码执行失败,所以这里统一把typeof global替换为typeof undefined
function removeGlobal() {
return {
transform(code, id) {
if (id.indexOf('worker.js') === -1) return null;
const commonjsCode = /typeof global/g;
const transformedCode = code.replace(commonjsCode, 'typeof undefined');
return {
code: transformedCode,
map: { mappings: '' }
};
}
};
}
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}');`;
module.exports = [
{
input: 'index.js',
plugins: [
resolve({
browser: true,
preferBuiltins: false
}),
commonjs({
// global keyword handling causes Webpack compatibility issues, so we disabled it:
// https://github.com/mapbox/mapbox-gl-js/pull/6956
ignoreGlobal: true
})
].concat(plugins),
external: ['maptalks'],
output: {
globals: {
'maptalks': 'maptalks'
},
banner,
outro,
extend: true,
name: 'maptalks',
file: outputFile,
format: 'umd',
sourcemap: production ? false : 'inline',
},
watch: {
include: ['index.js']
}
},
{
input: 'index.js',
plugins: [
resolve({
browser: true,
preferBuiltins: false
}),
commonjs({
// global keyword handling causes Webpack compatibility issues, so we disabled it:
// https://github.com/mapbox/mapbox-gl-js/pull/6956
ignoreGlobal: true
})
].concat(plugins),
external: ['maptalks'],
output: {
globals: {
'maptalks': 'maptalks'
},
banner,
outro,
extend: true,
name: 'maptalks',
file: outputESFile,
format: 'es',
sourcemap: production ? false : 'inline',
},
watch: {
include: ['index.js']
}
}
];