aboutsummaryrefslogtreecommitdiffhomepage
path: root/rollup.config.js
blob: f5a22eb451e4cf3844a9c9e17b016a3f57c81fab (plain)
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
import node from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import terser from '@rollup/plugin-terser'
import { existsSync } from 'fs'
import { join } from 'path'
import { bundleStats } from 'rollup-plugin-bundle-stats'

const production = !process.env.ROLLUP_WATCH

const general = {
  output: [
    {
      dir: './dist',
      format: 'esm',
      entryFileNames: '[name].mjs',
      sourcemap: 'true',
    },
  ],
  watch: {
    clearScreen: false,
    include: ['src/**', 'mapclay/dist/mapclay.mjs'],
  },
  context: 'window',
  plugins: [
    {
      name: 'watch-mapclay',
      buildStart () {
        const mapclayPath = join(process.cwd(), 'mapclay', 'dist', 'mapclay.mjs')
        if (existsSync(mapclayPath)) {
          this.addWatchFile(mapclayPath)
        } else {
          console.warn('mapclay.mjs not found at:', mapclayPath)
        }
      },
    },
    {
      name: 'leader-line',
      transform (code, id) {
        if (id.includes('node_modules/leader-line/')) {
          return `${code}\nexport default LeaderLine;`
        }
        return null
      },
    },
    {
      name: 'mapclay',
      resolveId (source) {
        if (source === 'mapclay' && existsSync(join('.', 'mapclay'))) {
          return './mapclay/dist/mapclay.mjs'
        }
        return null
      },
    },
    node(),
    commonjs(),
    production && terser({
      keep_fnames: true,
    }),
    production && bundleStats(),
  ],
}

export default [
  {
    input: 'src/editor.mjs',
  },
  {
    input: 'src/dumbymap.mjs',
  },
]
  .map(config => ({ ...general, ...config }))
  .filter((config) => production || config.input.match(/editor/))