-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathrollup.config.js
More file actions
154 lines (149 loc) · 5.47 KB
/
rollup.config.js
File metadata and controls
154 lines (149 loc) · 5.47 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
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
import pkg from './package.json' with { type: 'json' };
import replace from '@rollup/plugin-replace';
import json from '@rollup/plugin-json';
import image from '@rollup/plugin-image';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import glslMinify from './rollup-plugin-glsl-minify.js';
import worker from 'rollup-plugin-worker-factory';
import dts from 'rollup-plugin-dts';
import postcss from 'rollup-plugin-postcss';
import autoprefixer from 'autoprefixer';
import assets from 'postcss-assets';
import terser from '@rollup/plugin-terser';
import license from 'rollup-plugin-license';
import { visualizer } from 'rollup-plugin-visualizer';
import tsc from 'typescript';
const CATALOG_URL = process.env.CATALOG_URL ?? 'https://catalog.weatherlayers.com';
function bundle(entrypoint, filename, format, options = {}) {
if (format === 'cjs') {
filename = filename.replace('.js', `${options.minimize ? '.min' : ''}.cjs`);
} else if (format === 'es') {
filename = filename.replace('.js', `${options.minimize ? '.min' : ''}.js`);
} else if (format === 'umd') {
filename = filename.replace('.js', `.umd${options.minimize ? '.min' : ''}.js`);
}
const bundleClient = filename.includes('client');
const bundleGl = filename.includes('deck');
if (!bundleClient && !bundleGl) {
throw new Error('Invalid state');
}
const banner = [
`Copyright (c) 2021-${new Date().getFullYear()} WeatherLayers.com`,
'',
...(bundleClient ? [`WeatherLayers Cloud Client ${pkg.version}`] : []),
...(bundleGl ? [`WeatherLayers GL ${pkg.version}`] : []),
'',
...(bundleClient ? ['A valid access token is required to use the library. Contact support@weatherlayers.com for details.'] : []),
...(bundleGl ? ['Package and source code is dual-licensed, the choice of license is MPL-2.0 or our License Terms of Use. Contact support@weatherlayers.com for details.'] : []),
'',
'Homepage - https://weatherlayers.com/',
'Demo - https://demo.weatherlayers.com/',
'Docs - https://docs.weatherlayers.com/',
...(bundleClient ? ['WeatherLayers Cloud Terms of Use - https://weatherlayers.com/terms-of-use.html'] : []),
...(bundleGl ? ['WeatherLayers GL License Terms of Use - https://weatherlayers.com/license-terms-of-use.html'] : []),
].join('\n');
return {
input: entrypoint,
output: {
file: filename,
format: format,
name: bundleClient ? 'WeatherLayersClient' : 'WeatherLayers',
globals: {
'@deck.gl/core': 'deck',
'@deck.gl/extensions': 'deck',
'@deck.gl/layers': 'deck',
'@luma.gl/core': 'luma',
'@luma.gl/engine': 'luma',
'geotiff': 'GeoTIFF',
},
},
external: [
...Object.keys(pkg.peerDependencies),
...(!options.resolve ? [
...Object.keys(pkg.dependencies),
'@babel/runtime/helpers/defineProperty',
'rollup-plugin-worker-factory/src/browser.js',
] : []),
],
plugins: [
replace({
preventAssignment: true,
__PACKAGE_VERSION__: `"${pkg.version}"`,
__PACKAGE_DATETIME__: `"${new Date().toISOString()}"`,
__CATALOG_URL__: `"${CATALOG_URL}"`,
}),
json(),
image(),
...(options.resolve ? [resolve()] : []),
babel({ babelHelpers: 'runtime' }),
commonjs(),
typescript({
typescript: tsc,
clean: options.stats,
}),
glslMinify({ minimize: options.minimize }),
worker({
plugins: [
resolve(),
commonjs(),
typescript({
typescript: tsc,
clean: options.stats,
tsconfigOverride: {
compilerOptions: {
target: 'es2016', // Fix support for Angular by downgrading to ES2016 target in WebWorkers, see https://github.com/angular/angular-cli/issues/22191
},
},
}),
],
type: 'browser',
}),
postcss({ plugins: [autoprefixer(), assets()], minimize: options.minimize }),
...(options.minimize ? [terser({ output: { comments: false } })] : []),
license({
banner: {
content: banner,
commentStyle: 'ignored',
},
}),
...(options.stats ? [visualizer({
filename: filename + '.stats.html',
})] : []),
],
};
}
export default commandLineArgs => {
return [
['src/client/index.ts', 'dist/weatherlayers-client.js'],
['src/deck/index.ts', 'dist/weatherlayers-deck.js'],
].map(([entrypoint, filename]) => [
...(!commandLineArgs.watch || commandLineArgs.format === 'cjs' ? [
bundle(entrypoint, filename, 'cjs'),
bundle(entrypoint, filename, 'cjs', { minimize: true }),
] : []),
...(!commandLineArgs.watch || commandLineArgs.format === 'es' ? [
bundle(entrypoint, filename, 'es'),
bundle(entrypoint, filename, 'es', { minimize: true }),
{
input: entrypoint,
output: {
file: filename.replace('.js', '.d.ts'),
format: 'es',
},
plugins: [
dts(),
json(),
image(),
postcss({ inject: false }),
],
},
] : []),
...(!commandLineArgs.watch || !commandLineArgs.format || commandLineArgs.format === 'umd' ? [
bundle(entrypoint, filename, 'umd', { resolve: true, stats: true }),
bundle(entrypoint, filename, 'umd', { resolve: true, minimize: true }),
] : [])
]).flat();
};