-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrollup.config.ts
69 lines (62 loc) · 2.01 KB
/
rollup.config.ts
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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {Plugin, RollupOptions} from 'rollup';
import cleanOnce from './build/rollup-plugin-clean-once';
import eslintPlugin from '@rollup/plugin-eslint';
import typescript from '@rollup/plugin-typescript';
import nodeResolve from '@rollup/plugin-node-resolve';
import prettierBuildStart from './build/rollup-plugin-prettier-build-start';
import staticFiles from './build/rollup-plugin-static-files';
import watch from './build/rollup-plugin-watch-additional';
function eslint(): Plugin {
return eslintPlugin({throwOnError: true});
}
function prettierSrc(): Plugin {
return prettierBuildStart('"src/**/*.(js|ts)"');
}
const TARGETS = [
['chrome', 'v3'],
['edge', 'v3'],
['firefox', 'v2'],
['safari', 'v2'],
];
const SITES = ['WA', 'MSGR', 'FB', 'IG'];
const contentScriptSteps: Array<RollupOptions> = SITES.map((site, index) => ({
input: `src/js/detect${site}Meta.ts`,
output: TARGETS.map(([target]) => ({
file: `dist/${target}/content${site}.js`,
format: 'iife',
})),
plugins: [cleanOnce(), typescript(), prettierSrc(), eslint()],
}));
const config: Array<RollupOptions> = contentScriptSteps.concat([
{
input: 'src/js/background.ts',
output: TARGETS.map(([target]) => ({
file: `dist/${target}/background.js`,
format: 'iife',
})),
plugins: [typescript(), prettierSrc(), eslint(), nodeResolve()],
},
{
input: 'src/js/popup.ts',
output: TARGETS.map(([target, version]) => ({
file: `dist/${target}/popup.js`,
format: 'iife',
plugins: [staticFiles(`config/${version}/`)],
})),
plugins: [
typescript(),
prettierSrc(),
eslint(),
staticFiles(['images/', 'src/css/', 'src/html/']),
staticFiles('_locales/', {keepDir: true}),
watch(['images/', 'src/css/', 'src/html/', '_locales/', 'config/']),
],
},
]);
export default config;