forked from jsxtools/focus-within
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.rollup.js
64 lines (57 loc) · 1.47 KB
/
.rollup.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
import babel from 'rollup-plugin-babel';
import { terser } from 'rollup-plugin-terser';
const isBrowser = String(process.env.NODE_ENV).includes('browser');
const isCLI = String(process.env.NODE_ENV).includes('cli');
const isPostCSS = String(process.env.NODE_ENV).includes('postcss');
const targets = isCLI || isPostCSS || !isBrowser ? { node: 6 } : 'last 2 versions, not dead';
const input = `src/${isCLI ? 'cli' : isPostCSS ? 'postcss' : 'browser'}.js`;
const output = isCLI
? { file: 'cli.js', format: 'cjs' }
: isBrowser
? { file: 'browser.js', format: 'cjs' }
: isPostCSS
? [
{ file: 'postcss.js', format: 'cjs', sourcemap: true },
{ file: 'postcss.mjs', format: 'esm', sourcemap: true }
] : [
{ file: 'index.js', format: 'cjs', sourcemap: true },
{ file: 'index.mjs', format: 'esm', sourcemap: true }
];
const plugins = [
babel({
presets: [
['@babel/env', { targets }]
]
})
].concat(isBrowser
? [
trimContentForBrowser(),
terser()
]
: isCLI
? [
trimContentForBrowser(),
addHashBang()
]
: []);
export default { input, output, plugins };
function addHashBang() {
return {
name: 'add-hash-bang',
renderChunk(code) {
const updatedCode = `#!/usr/bin/env node\n\n${code}`;
return updatedCode;
}
};
}
function trimContentForBrowser() {
return {
name: 'trim-content-for-browser',
renderChunk(code) {
const updatedCode = code
.replace(/'use strict';\n*/, '')
.replace(/\n*module\.exports = focusWithin;/, '');
return updatedCode;
}
};
}