forked from vaadin/router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
90 lines (83 loc) · 2.56 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
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import pkg from './package.json' assert {type: "json"};
const plugins = [
// The 'node-resolve' plugin allows Rollup to resolve bare module imports like
// in `import {pathToRegexp} from 'path-to-regexp';`
resolve(),
];
const config = [
// ES module bundle, not transpiled (for the browsers that support ES modules)
{
input: 'index.js',
output: {
format: 'es',
file: pkg.main,
sourcemap: true,
},
plugins
},
// UMD bundle, transpiled (for the browsers that do not support ES modules).
// Also works in Node.
{
input: 'index.polyfilled.js',
output: {
format: 'umd',
file: pkg.main.replace('.js', '.umd.js'),
sourcemap: true,
name: 'Vaadin',
extend: true,
},
plugins: [
...plugins,
babel({
presets: [
['@babel/preset-env', {
// Run `npm run browserslist` to see the percent of users covered
// by this browsers selection
targets: {
browsers: pkg.browserslist
},
// To see which browsers are targeted, and which JS features are
// polyfilled, uncomment the next line and run `npm run build`
// debug: true,
}]
],
})
]
},
];
const sourceFiles = new Map([
['src/resolver/matchPath.js', 'matchPath'],
['src/resolver/matchRoute.js', 'matchRoute'],
['src/resolver/resolver.js', 'Resolver'],
['src/resolver/generateUrls.js', 'generateUrls'],
['src/triggers/click.js', 'CLICK'],
['src/triggers/popstate.js', 'POPSTATE'],
['src/triggers/setNavigationTriggers.js', 'setNavigationTriggers'],
['src/transitions/animate.js', 'animate'],
]);
const coverageBundles = Array.from(sourceFiles.entries()).map(([file, name]) => {
return {
input: file,
external: (id, parent, isResolved) => {
return !!parent && sourceFiles.has(
path.relative(__dirname, path.resolve(path.dirname(parent), id)));
},
output: {
format: 'iife',
file: file.replace('src', 'dist/test-iife'),
banner: '/* This file is automatically generated by `npm run build` */',
name: `VaadinTestNamespace.${name}`,
globals: (id) => {
const name = sourceFiles.get(path.relative(__dirname, id));
return name ? `VaadinTestNamespace.${name}` : id;
},
},
plugins,
};
});
// IIFE bundles for individual source files (for coverage testing)
config.push(...coverageBundles);
export default config;