forked from maplibre/maplibre-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.style-spec.ts
56 lines (53 loc) · 2.17 KB
/
rollup.config.style-spec.ts
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
import path, {dirname} from 'path';
import replace from '@rollup/plugin-replace';
import commonjs from '@rollup/plugin-commonjs';
import unassert from 'rollup-plugin-unassert';
import json from '@rollup/plugin-json';
import {fileURLToPath, pathToFileURL} from 'url';
import {RollupOptions} from 'rollup';
import {nodeResolve} from './build/rollup_plugins';
import typescript from '@rollup/plugin-typescript';
const esm = 'esm' in process.env;
const config: RollupOptions[] = [{
input: 'src/style-spec/style-spec.ts',
output: {
name: 'maplibreGlStyleSpecification',
file: `dist/style-spec/${esm ? 'index.mjs' : 'index.js'}`,
format: esm ? 'esm' : 'umd',
sourcemap: true
},
plugins: [
{
name: 'dep-checker',
resolveId(source, importer) {
// Some users reference modules within style-spec package directly, instead of the bundle
// This means that files within the style-spec package should NOT import files from the parent maplibre-gl-js tree.
// This check will cause the build to fail on CI allowing these issues to be caught.
if (importer && !importer.includes('node_modules')) {
const resolvedPath = path.join(importer, source);
const importMetaUrl = pathToFileURL(__filename).toString();
const fromRoot = path.relative(dirname(fileURLToPath(importMetaUrl)), resolvedPath);
if (fromRoot.length > 2 && fromRoot.slice(0, 2) === '..') {
throw new Error(`Module ${importer} imports ${source} from outside the style-spec package root directory.`);
}
}
return null;
}
},
// https://github.com/zaach/jison/issues/351
replace({
preventAssignment: true,
include: /\/jsonlint-lines-primitives\/lib\/jsonlint.js/,
delimiters: ['', ''],
values: {
'_token_stack:': ''
}
}),
json(),
unassert(),
nodeResolve,
typescript(),
commonjs()
]
}];
export default config;