/
rollup.config.js
80 lines (74 loc) · 2.24 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
import babel from '@rollup/plugin-babel';
import * as path from 'path';
import nodeResolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import { rollupPluginAriaQuery } from '../rollup-plugin-aria-query';
import { rollupPluginDomAccessibilityApi } from '../rollup-plugin-dom-accessibility-api';
const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx'];
const stubs = {
'pretty-format': `
const prettyFormat = () => {}
prettyFormat.plugins = { DOMElement: {}, DOMCollection: {} }
export default prettyFormat
`,
[require.resolve('@testing-library/dom/dist/pretty-dom')]: `
import {addToElementCache} from ${JSON.stringify(
path.join(process.cwd(), 'src', 'serialize', 'index.ts'),
)}
export const prettyDOM = (dom, maxLength, options) => {
return addToElementCache(dom)
}
`,
};
/** @type {import('rollup').Plugin} */
const stubPlugin = {
name: 'stub',
async resolveId(id) {
if (stubs[id]) return id;
return null;
},
async load(id) {
if (stubs[id]) return stubs[id];
return null;
},
};
/**
* Sometimes when testing-library logs messages it uses el.cloneNode() before it logs them
* Normally that would be fine, but for logging in the browser,
* it makes hovering over the element in devtools not work
* So we are removing the cloneNodes to fix hovering
* @type {import('rollup').Plugin}
*/
const removeCloneNodePlugin = {
name: 'remove-clone-node',
async transform(code) {
return code.replace(/\.cloneNode\((?:false|true)\)/g, '');
},
};
/** @type {import('rollup').RollupOptions} */
const config = {
input: ['src/pptr-testing-library-client/index.ts'],
plugins: [
rollupPluginAriaQuery(),
rollupPluginDomAccessibilityApi(),
stubPlugin,
babel({ babelHelpers: 'bundled', extensions }),
nodeResolve({ extensions }),
removeCloneNodePlugin,
terser({
ecma: 2019,
module: true,
compress: {
passes: 3,
global_defs: {
jest: false,
'globalVar.process': undefined,
},
},
}),
],
external: [],
treeshake: { moduleSideEffects: 'no-external' },
output: { file: 'dist/pptr-testing-library-client.js', preferConst: true },
};
export default config;