Debian Codegraph @

.config/rollup.config.js

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 import pkg from '../package.json' with { type: 'json' }
2 import babel from '@rollup/plugin-babel'
3 import resolve from '@rollup/plugin-node-resolve'
4 import commonjs from '@rollup/plugin-commonjs'
5 import filesize from 'rollup-plugin-filesize'
6 import terser from '@rollup/plugin-terser'
7
8 const buildDate = Date()
9
10 const headerLong = `/*!
11 * ${pkg.name} - ${pkg.description}
12 * @version ${pkg.version}
13 * ${pkg.homepage}
14 *
15 * @copyright ${pkg.author}
16 * @license ${pkg.license}
17 *
18 * BUILT: ${buildDate}
19 */;`
20
21 const headerShort = `/*! ${pkg.name} v${pkg.version} ${pkg.license}*/;`
22
23 const getBabelConfig = (node = false) => {
24 let targets = pkg.browserslist
25 const plugins = [
26 [
27 '@babel/transform-runtime',
28 {
29 version: '^7.24.7',
30 regenerator: false,
31 useESModules: true
32 }
33 ],
34 [
35 'polyfill-corejs3',
36 {
37 method: 'usage-pure'
38 }
39 ]
40 ]
41
42 if (node) {
43 targets = 'maintained node versions'
44 }
45
46 return babel({
47 include: 'src/**',
48 babelHelpers: 'runtime',
49 babelrc: false,
50 targets: targets,
51 presets: [
52 [
53 '@babel/preset-env',
54 {
55 modules: false,
56 // useBuildins and plugin-transform-runtime are mutually exclusive
57 // https://github.com/babel/babel/issues/10271#issuecomment-528379505
58 // use babel-polyfills when released
59 useBuiltIns: false,
60 bugfixes: true,
61 loose: true
62 }
63 ]
64 ],
65 plugins
66 })
67 }
68
69 // When few of these get mangled nothing works anymore
70 // We loose literally nothing by let these unmangled
71 const classes = [
72 'A',
73 'ClipPath',
74 'Defs',
75 'Element',
76 'G',
77 'Image',
78 'Marker',
79 'Path',
80 'Polygon',
81 'Rect',
82 'Stop',
83 'Svg',
84 'Text',
85 'Tspan',
86 'Circle',
87 'Container',
88 'Dom',
89 'Ellipse',
90 'Gradient',
91 'Line',
92 'Mask',
93 'Pattern',
94 'Polyline',
95 'Shape',
96 'Style',
97 'Symbol',
98 'TextPath',
99 'Use'
100 ]
101
102 const config = (node, min, esm = false) => ({
103 input: node || esm ? './src/main.js' : './src/svg.js',
104 output: {
105 file: esm
106 ? './dist/svg.esm.js'
107 : node
108 ? './dist/svg.node.cjs'
109 : min
110 ? './dist/svg.min.js'
111 : './dist/svg.js',
112 format: esm ? 'esm' : node ? 'cjs' : 'iife',
113 name: 'SVG',
114 sourcemap: true,
115 banner: headerLong,
116 // remove Object.freeze
117 freeze: false
118 },
119 treeshake: {
120 // property getter have no sideeffects
121 propertyReadSideEffects: false
122 },
123 plugins: [
124 resolve({ browser: !node }),
125 commonjs(),
126 getBabelConfig(node),
127 filesize(),
128 !min
129 ? {}
130 : terser({
131 mangle: {
132 reserved: classes
133 },
134 output: {
135 preamble: headerShort
136 }
137 })
138 ]
139 })
140
141 // [node, minified, esm]
142 const modes = [[false], [false, true], [true], [false, false, true]]
143
144 export default modes.map((m) => config(...m))