-
Notifications
You must be signed in to change notification settings - Fork 14
/
rollup.config.mjs
79 lines (76 loc) · 2.34 KB
/
rollup.config.mjs
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
import { readFileSync } from 'fs';
import { join } from 'path';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import importAssets from 'rollup-plugin-import-assets';
import { defineConfig } from 'rollup';
import scss from 'rollup-plugin-scss';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import externalGlobals from 'rollup-plugin-external-globals';
import replace from '@rollup/plugin-replace';
import del from 'rollup-plugin-delete';
import * as sass from 'sass';
const manifest = JSON.parse(readFileSync(join('.', 'plugin.json'), 'utf-8'));
export default defineConfig({
input: './src/index.tsx',
plugins: [
del({ targets: './dist/*', force: true }),
json({ compact: true }),
typescript({
include: ['src/**/*.ts', 'src/**/*.tsx'],
}),
commonjs(),
nodePolyfills(),
nodeResolve({
browser: true,
}),
scss({
output: false,
sourceMap: false,
include: ['src/styles/**/*.scss', 'src/styles/**/*.sass'],
watch: 'src/styles',
sass: sass,
}),
externalGlobals({
react: 'SP_REACT',
'react-dom': 'SP_REACTDOM',
'@decky/ui': 'DFL',
'@decky/manifest': JSON.stringify(manifest),
}),
replace({
preventAssignment: false,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
'process.env.ROLLUP_ENV': JSON.stringify(process.env.ROLLUP_ENV),
}),
importAssets({
publicPath: `http://127.0.0.1:1337/plugins/${manifest.name}/`,
include:[
/\.gif$/i,
/\.jpg$/i,
/\.png$/i,
/\.svg$/i,
/\.webm$/i,
/\.webp$/i,
/\.mp4$/i,
],
}),
],
context: 'window',
external: ['react', 'react-dom', '@decky/ui'],
treeshake: {
// Assume all external modules have imports with side effects (the default) while allowing decky libraries to treeshake
pureExternalImports: {
pure: ['@decky/ui', '@decky/api'],
},
preset: 'smallest',
},
output: {
dir: 'dist',
format: 'esm',
sourcemap: true,
sourcemapPathTransform: (relativeSourcePath) => relativeSourcePath.replace(/^\.\.\//, `decky://decky/plugin/${encodeURIComponent(manifest.name)}/`),
exports: 'default',
},
});