aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/rollup.config.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rollup.config.js')
-rw-r--r--scripts/rollup.config.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js
new file mode 100644
index 0000000..d4af05f
--- /dev/null
+++ b/scripts/rollup.config.js
@@ -0,0 +1,63 @@
1import node from '@rollup/plugin-node-resolve'
2import commonjs from '@rollup/plugin-commonjs'
3import terser from '@rollup/plugin-terser'
4import { existsSync } from 'fs'
5import { join } from 'path'
6import { bundleStats } from 'rollup-plugin-bundle-stats'
7
8const production = !process.env.ROLLUP_WATCH
9
10const general = {
11 output: [
12 {
13 dir: './dist',
14 format: 'esm',
15 entryFileNames: '[name].mjs',
16 sourcemap: 'true',
17 },
18 ],
19 watch: {
20 clearScreen: false,
21 include: ['src/**', 'node_modules/mapclay/dist/mapclay.mjs'],
22 },
23 context: 'window',
24 plugins: [
25 {
26 name: 'watch-mapclay',
27 buildStart () {
28 const mapclayPath = join(process.cwd(), 'node_modules', 'mapclay', 'dist', 'mapclay.mjs')
29 if (existsSync(mapclayPath)) {
30 this.addWatchFile(mapclayPath)
31 } else {
32 console.warn('mapclay.mjs not found at:', mapclayPath)
33 }
34 },
35 },
36 {
37 name: 'leader-line',
38 transform (code, id) {
39 if (id.includes('node_modules/leader-line/')) {
40 return `${code}\nexport default LeaderLine;`
41 }
42 return null
43 },
44 },
45 node(),
46 commonjs(),
47 production && terser({
48 keep_fnames: true,
49 }),
50 production && bundleStats(),
51 ],
52}
53
54export default [
55 {
56 input: 'src/editor.mjs',
57 },
58 {
59 input: 'src/dumbymap.mjs',
60 },
61]
62 .map(config => ({ ...general, ...config }))
63 .filter((config) => production || config.input.match(/editor/))