forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
104 lines (94 loc) · 2.75 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
import sucrase from '@rollup/plugin-sucrase';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import cleanup from 'rollup-plugin-cleanup';
import styles from 'rollup-plugin-styles';
import {string} from 'rollup-plugin-string';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
import svelte from 'rollup-plugin-svelte';
import lightning from 'unplugin-lightningcss/rollup';
import {Features} from 'lightningcss';
import svelteConfig from './svelte.config.js';
const noise = new Set(['index', 'dist', 'src', 'source', 'distribution', 'node_modules', 'main', 'esm', 'cjs', 'build', 'built']);
/** @type {import('rollup').RollupOptions} */
const rollup = {
input: {
'options': './source/options.tsx',
'welcome': './source/welcome.svelte',
'header': './source/options/header.svelte',
'background': './source/background.ts',
'refined-github': './source/refined-github.ts',
'content-script': './source/content-script.ts',
'resolve-conflicts': './source/resolve-conflicts.ts',
},
output: {
dir: 'distribution/assets',
preserveModules: true,
preserveModulesRoot: 'source',
assetFileNames: '[name][extname]', // For CSS
entryFileNames(chunkInfo) {
if (chunkInfo.name.includes('node_modules')) {
const cleanName = chunkInfo.name
.split('/')
.filter(part => !noise.has(part))
.join('-');
return `npm/${cleanName}.js`;
}
return chunkInfo.name.replace('build/__snapshots__/', '') + '.js';
},
},
watch: {
clearScreen: false,
},
// TODO: Drop after https://github.com/sindresorhus/memoize/issues/102
context: 'globalThis',
plugins: [
del({
targets: ['distribution/assets'],
runOnce: true, // `false` would be nice, but it deletes the files too early, causing two extension reloads
}),
lightning({
options: {
include: Features.Nesting,
},
}),
svelte(svelteConfig),
json(),
styles({
mode: 'extract',
url: false,
}),
string({
include: '**/*.gql',
}),
alias({
entries: [
{find: 'react', replacement: 'dom-chef'},
],
}),
sucrase({
transforms: ['typescript', 'jsx'],
// Output modern JS
disableESTransforms: true,
// Drop `__self` in JSX https://github.com/alangpierce/sucrase/issues/232#issuecomment-468898878
production: true,
}),
resolve({browser: true}),
commonjs(),
copy({
targets: [
{src: './source/manifest.json', dest: 'distribution'},
{src: './source/*.+(html|png)', dest: 'distribution/assets'},
],
}),
cleanup(),
],
};
if (process.env.RELATIVE_CI_STATS) {
rollup.plugins.push(webpackStatsPlugin());
}
export default rollup;