aboutsummaryrefslogtreecommitdiffhomepage
path: root/rollup.config.js
blob: d04eb4e53f477c439174cc3d0c90b9bc198ab68c (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
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';

const production = !process.env.ROLLUP_WATCH;
const general = {
  output: [
    {
      dir: './dist',
      format: 'esm',
      entryFileNames: '[name].mjs',
    }
  ],
  watch: {
    clearScreen: false,
    include: ["src/**", "mapclay/dist/mapclay.mjs"]
  },
  context: "window",
  plugins: [
    {
      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(),
  ],
}

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