-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrollup.config.js
More file actions
61 lines (57 loc) · 1.54 KB
/
rollup.config.js
File metadata and controls
61 lines (57 loc) · 1.54 KB
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
var path = require('path');
var legacy = require('./scripts/legacy_bundle.js');
function buildConfig(opts) {
var deps = opts.deps || [];
var entryFile = opts.minimal ? 'src/proj-minimal.js' : 'src/proj.js';
var outBase = opts.outBase;
var libraryDirs = [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules/geographiclib/src')
];
return [
{
input: '\0mproj-entry-cjs',
plugins: [legacyPlugin(entryFile, deps, libraryDirs, 'cjs')],
output: {
file: path.resolve(__dirname, 'dist/' + outBase + '.js'),
format: 'cjs'
}
},
{
input: '\0mproj-entry-esm',
plugins: [legacyPlugin(entryFile, deps, libraryDirs, 'esm')],
output: {
file: path.resolve(__dirname, 'dist/' + outBase + '.mjs'),
format: 'esm'
}
}
];
}
function legacyPlugin(entryFile, deps, libraryDirs, format) {
var id = format === 'esm' ? '\0mproj-entry-esm' : '\0mproj-entry-cjs';
return {
name: 'legacy-proj-bundle-' + format,
resolveId: function(source) {
if (source === id) {
return id;
}
return null;
},
load: function(source) {
if (source !== id) {
return null;
}
var output = legacy.createBundleWithMeta({
entryFile: entryFile,
projectionDeps: deps,
libraryDirs: libraryDirs,
format: format
});
output.files.forEach(function(filePath) {
this.addWatchFile(filePath);
}, this);
return output.code;
}
};
}
module.exports = buildConfig;