forked from TimLuq/schematron-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
143 lines (132 loc) · 4.01 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
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
import resolve from 'rollup-plugin-node-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import pkg from './package.json';
import { resolve as resolvePath } from "path";
// function terser() { return { name: "terser" }; }
function idResolver(options = {}) {
return {
name: 'xpath-resolver',
resolveId(importee) {
if (importee === "xpath") {
return resolvePath(process.cwd(), "node_modules", "xpath", "xpath.js");
}
if (importee === "regenerator-runtime/runtime") {
return resolvePath(process.cwd(), "node_modules", "regenerator-runtime", "runtime.js");
}
return (options.resolveId && options.resolveId[importee]) || null;
}
};
}
function babelConf(targets) {
return {
plugins: [ "@babel/plugin-syntax-dynamic-import" ],
presets: [['@babel/env', { targets }]],
};
}
export default [
// browser-friendly UMD build
{
input: 'esm/browser.js',
external: ['fs', 'node-fetch', 'xmldom', 'crypto', './dom-parser'],
output: {
name: pkg.name,
sourcemap: true,
file: pkg.browser,
format: 'umd',
exports: 'named',
},
plugins: [
idResolver(),
sourcemaps(),
commonjs(),
babel(babelConf("> 5%, not dead")),
terser(),
]
},
// bundle [parse5 parser](https://www.npmjs.com/package/parse5), which is under MIT license
{
input: 'esm/dom-parser.js',
external: ["parse5/lib/parser/index.js"],
output: [
{
banner: "// minimized xmldom parser: https://www.npmjs.com/package/xmldom",
name: "dom-parser",
sourcemap: true,
file: "build/dom-parser.js",
format: 'umd',
exports: 'named',
},
{
banner: "// minimized xmldom parser: https://www.npmjs.com/package/xmldom",
name: "dom-parser",
sourcemap: true,
file: "build/dom-parser.mjs",
format: 'es',
exports: 'named',
},
],
plugins: [
resolve(),
sourcemaps(),
commonjs(),
babel(babelConf("> 5%, not dead")),
terser(),
]
},
{
input: 'esm/schematron-runner.js',
external: ['fs', 'node-fetch', 'xpath', 'xmldom', 'crypto', './dom-parser.js'],
output: [
{ file: pkg.cjs, sourcemap: true, format: 'cjs', exports: 'named' },
],
plugins: [
idResolver({ resolveId: {
"./dom-parser": "./dom-parser.js",
}}),
resolve(),
sourcemaps(),
babel(babelConf({ node: "8" })),
terser(),
]
},
{
input: 'esm/schematron-runner.js',
external: ['fs', 'node-fetch', 'xpath', 'xmldom', 'crypto', './dom-parser.mjs'],
output: [
{ file: pkg.module, sourcemap: true, format: 'es', exports: 'named' },
],
plugins: [
idResolver({ resolveId: {
"./dom-parser": "./dom-parser.mjs",
}}),
resolve(),
sourcemaps(),
babel(babelConf({ chrome: "64" })),
terser(),
]
},
{
input: 'esm/schematron-runner.js',
external: ['fs', 'node-fetch', 'xpath', 'xmldom', './dom-parser'],
output: { file: pkg.cjsDebug, sourcemap: true, format: 'cjs', exports: 'named' },
plugins: [
sourcemaps(),
]
},
{
input: 'esm/bin.js',
external: ['fs', 'node-fetch', 'xpath', 'xmldom', 'crypto', './dom-parser'],
output: [
{ file: pkg.bin, sourcemap: true, format: 'cjs', exports: 'named', banner: "#!/usr/bin/env node\ntry { require('source-map-support').install(); } catch (_) {}" },
],
plugins: [
resolve(),
sourcemaps(),
// babel(babelConf({ node: "8" })),
// terser(),
]
}
];