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.js55
1 files changed, 50 insertions, 5 deletions
diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js
index d4af05f..7dc9f75 100644
--- a/scripts/rollup.config.js
+++ b/scripts/rollup.config.js
@@ -5,7 +5,25 @@ import { existsSync } from 'fs'
5import { join } from 'path' 5import { join } from 'path'
6import { bundleStats } from 'rollup-plugin-bundle-stats' 6import { bundleStats } from 'rollup-plugin-bundle-stats'
7 7
8const production = !process.env.ROLLUP_WATCH 8const prod = process.env.PRODUCTION
9const addon = process.env.ADDON
10
11function resolve (file, origin) {
12 // Your way to resolve local include path
13}
14
15function pathResolve (options) {
16 return {
17 resolveId: function (file, origin) {
18 // Your local include path must either starts with `./` or `../`
19 if (file.startsWith('./') || file.startsWith('../')) {
20 // Return an absolute include path
21 return resolve(file, origin)
22 }
23 return null // Continue to the next plugins!
24 },
25 }
26}
9 27
10const general = { 28const general = {
11 output: [ 29 output: [
@@ -13,7 +31,6 @@ const general = {
13 dir: './dist', 31 dir: './dist',
14 format: 'esm', 32 format: 'esm',
15 entryFileNames: '[name].mjs', 33 entryFileNames: '[name].mjs',
16 sourcemap: 'true',
17 }, 34 },
18 ], 35 ],
19 watch: { 36 watch: {
@@ -42,12 +59,13 @@ const general = {
42 return null 59 return null
43 }, 60 },
44 }, 61 },
62 pathResolve(),
45 node(), 63 node(),
46 commonjs(), 64 commonjs(),
47 production && terser({ 65 prod && terser({
48 keep_fnames: true, 66 keep_fnames: true,
49 }), 67 }),
50 production && bundleStats(), 68 prod && bundleStats(),
51 ], 69 ],
52} 70}
53 71
@@ -60,4 +78,31 @@ export default [
60 }, 78 },
61] 79]
62 .map(config => ({ ...general, ...config })) 80 .map(config => ({ ...general, ...config }))
63 .filter((config) => production || config.input.match(/editor/)) 81 .filter(config => {
82 if (addon) return config.input.match(/dumbymap/)
83 if (!prod) return config.input.match(/editor/)
84 })
85 .map(config => {
86 if (!addon) return config
87
88 config.output.forEach(o => o.dir = './addon')
89 config.plugins.push({
90 name: 'remove-exports',
91 transform (code, id) {
92 if (id.includes(config.input)) {
93 // remove export keyword for addon
94 const transformedCode = code.replace(/\n(\s*)export\s*/g, '$1')
95 return {
96 code: [
97 transformedCode,
98 'window.generateMaps = generateMaps',
99 'window.mapclay = mapclay',
100 ].join('\n'),
101 }
102 }
103 return null
104 },
105 })
106
107 return config
108 })