forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
64 lines (60 loc) · 2.29 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
import sourcemaps from 'rollup-plugin-sourcemaps';
import {plugins} from './build/rollup_plugins';
const production = process.env.BUILD === 'production';
const outputFile = production ? 'dist/mapbox-gl.js' : 'dist/mapbox-gl-dev.js';
const config = [{
// First, use code splitting to bundle GL JS into three "chunks":
// - rollup/build/index.js: the main module, plus all its dependencies not shared by the worker module
// - rollup/build/worker.js: the worker module, plus all dependencies not shared by the main module
// - rollup/build/chunk1.js: the set of modules that are dependencies of both the main module and the worker module
//
// This is also where we do all of our source transformations: removing
// flow annotations, transpiling ES6 features using buble, inlining shader
// sources as strings, etc.
input: ['src/index.js', 'src/source/worker.js'],
output: {
dir: 'rollup/build/mapboxgl',
format: 'amd',
sourcemap: 'inline',
indent: false
},
experimentalCodeSplitting: true,
treeshake: production,
plugins: plugins()
}, {
// Next, bundle together the three "chunks" produced in the previous pass
// into a single, final bundle. See 'intro:' below and rollup/mapboxgl.js
// for details.
input: 'rollup/mapboxgl.js',
output: {
name: 'mapboxgl',
file: outputFile,
format: 'umd',
sourcemap: production ? true : 'inline',
indent: false,
intro: `
let shared, worker, mapboxgl;
// define gets called three times: one for each chunk. we rely on the order
// they're imported to know which is which
function define(_, chunk) {
if (!shared) {
shared = chunk;
} else if (!worker) {
worker = chunk;
} else {
var workerBundleString = 'var sharedChunk = {}; (' + shared + ')(sharedChunk); (' + worker + ')(sharedChunk);'
var sharedChunk = {};
shared(sharedChunk);
mapboxgl = chunk(sharedChunk);
mapboxgl.workerUrl = window.URL.createObjectURL(new Blob([workerBundleString], { type: 'text/javascript' }));
}
}`
},
treeshake: false,
plugins: [
// Ingest the sourcemaps produced in the first step of the build.
// This is the only reason we use Rollup for this second pass
sourcemaps()
],
}];
export default config