-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
109 lines (100 loc) · 2.67 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
import babel from '@rollup/plugin-babel';
import nodeResolve from '@rollup/plugin-node-resolve';
import dts from 'rollup-plugin-dts';
import accessibilityConfig from './src/accessibility/rollup.config.js';
import jestDomConfig from './src/jest-dom/rollup.config.js';
import pptrTestingLibraryConfig from './src/pptr-testing-library-client/rollup.config.js';
import userUtilsConfig from './src/user-util/rollup.config.js';
const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx'];
const external = [
'puppeteer',
'source-map',
'acorn',
'es-module-lexer',
'cjs-module-lexer',
'rollup',
'@rollup/plugin-commonjs',
'esbuild',
/postcss/,
'@axe-core/puppeteer',
];
/** @type {import('rollup').RollupOptions} */
const mainConfig = {
input: ['src/index.ts'],
output: [
{
format: 'esm',
dir: 'dist/esm',
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs',
},
{
format: 'cjs',
dir: 'dist/cjs',
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs',
dynamicImportInCjs: false,
externalLiveBindings: false,
interop: (id) => {
if (id === 'puppeteer') return 'esModule';
return 'auto';
},
},
],
plugins: [
babel({ babelHelpers: 'bundled', extensions }),
nodeResolve({ extensions }),
bundlePlugin(),
],
external,
};
/** @type {import('rollup').RollupOptions} */
const typesConfig = {
input: 'src/index.ts',
output: [
{ file: 'dist/index.d.ts', format: 'es' },
{ file: 'dist/index.d.cts', format: 'es' },
{ file: 'dist/index.d.mts', format: 'es' },
],
external: [...external, 'polka', 'axe-core'],
plugins: [dts({ respectExternal: true })],
};
export default [
mainConfig,
userUtilsConfig,
accessibilityConfig,
jestDomConfig,
pptrTestingLibraryConfig,
typesConfig,
];
/**
* Creates sub-bundles when you do `import fileName from "bundle:./path-here"
* Mostly taken from https://github.com/preactjs/wmr/blob/1.0.0/src/plugins/bundle-plugin.js
*
* @returns {import('rollup').Plugin}
*/
function bundlePlugin() {
return {
name: 'bundle-plugin',
async resolveId(id, importer) {
if (!id.startsWith('bundle:')) return;
const resolved = await this.resolve(id.slice(7), importer, {
skipSelf: true,
});
if (resolved) {
resolved.id = `\0bundle:${resolved.id}`;
}
return resolved;
},
async load(id) {
if (!id.startsWith('\0bundle:')) return;
id = id.slice(8);
const fileId = this.emitFile({
type: 'chunk',
id,
});
this.addWatchFile(id);
return `export default import.meta.ROLLUP_FILE_URL_${fileId}`;
},
};
}