forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
131 lines (120 loc) · 3.3 KB
/
Copy pathrollup.config.js
File metadata and controls
131 lines (120 loc) · 3.3 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import sucrase from '@rollup/plugin-sucrase';
import browserslist from 'browserslist';
import {browserslistToTargets, Features} from 'lightningcss';
import cleanup from 'rollup-plugin-cleanup';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import {string} from 'rollup-plugin-string';
import styles from 'rollup-plugin-styles';
import svelte from 'rollup-plugin-svelte';
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
import lightning from 'unplugin-lightningcss/rollup';
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',
graphql: './source/graphql.svelte',
header: './source/options/header.svelte',
'storage-usage': './source/options/storage-usage.svelte',
'version-info': './source/options/version-info.svelte',
background: './source/background.ts',
'refined-github': './source/refined-github.ts',
'content-script': './source/content-script.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',
onwarn(warning, defaultHandler) {
if (
warning.code === 'CIRCULAR_DEPENDENCY'
&& warning.ids?.every(id => id.includes('/svelte/'))
) {
return;
}
defaultHandler(warning);
},
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,
// Lighting issue: https://github.com/parcel-bundler/lightningcss/issues/826#issuecomment-2453982986
targets: browserslistToTargets(browserslist('chrome 123, firefox 126, iOS 17.5')),
},
}),
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;