-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
52 lines (45 loc) · 1.41 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
import path from 'path';
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import shebang from 'rollup-plugin-preserve-shebang';
const devModeReplace = replace({
__DEV__: process.env.BUILD !== 'production',
});
const nodePlugins = [shebang(), typescript(), resolve(), devModeReplace];
const browserPlugins = [
// CommonJS plugin is necessary to expand imports inline,
// otherwise you get require() calls in the bundle
typescript({ module: 'CommonJS' }),
resolve(),
commonjs({ extensions: ['.js', '.ts'] }),
devModeReplace,
];
const files = [
'src/cli/main.ts',
'src/cli/support.ts',
'src/cli/commands/action.ts',
'src/cli/commands/extension.ts',
'src/cli/commands/json.ts',
'src/cli/commands/ls.ts',
'src/cli/commands/seek.ts',
'src/extension/background.ts',
'src/extension/content.ts',
'src/host/main.ts',
'src/install.ts',
'src/uninstall.ts',
];
const config = files.map((file) => {
const isForBrowser = file.includes('/extension/');
return {
input: file,
output: {
file: file.replace('src/', 'dist/').replace('.ts', '.js'),
format: isForBrowser ? 'iife' : 'cjs',
name: isForBrowser ? path.basename(file, '.ts') : undefined,
},
plugins: isForBrowser ? browserPlugins : nodePlugins,
};
});
export default config;