diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rollup.config.js | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js index d4af05f..434bd85 100644 --- a/scripts/rollup.config.js +++ b/scripts/rollup.config.js | |||
@@ -5,7 +5,25 @@ import { existsSync } from 'fs' | |||
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { bundleStats } from 'rollup-plugin-bundle-stats' | 6 | import { bundleStats } from 'rollup-plugin-bundle-stats' |
7 | 7 | ||
8 | const production = !process.env.ROLLUP_WATCH | 8 | const prod = process.env.PRODUCTION |
9 | const addon = process.env.ADDON | ||
10 | |||
11 | function resolve (file, origin) { | ||
12 | // Your way to resolve local include path | ||
13 | } | ||
14 | |||
15 | function 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 | ||
10 | const general = { | 28 | const 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,32 @@ 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 | return true | ||
85 | }) | ||
86 | .map(config => { | ||
87 | if (!addon) return config | ||
88 | |||
89 | config.output.forEach(o => { o.dir = './addon' }) | ||
90 | config.plugins.push({ | ||
91 | name: 'remove-exports', | ||
92 | transform (code, id) { | ||
93 | if (id.includes(config.input)) { | ||
94 | // remove export keyword for addon | ||
95 | const transformedCode = code.replace(/\n(\s*)export\s*/g, '$1') | ||
96 | return { | ||
97 | code: [ | ||
98 | transformedCode, | ||
99 | 'window.generateMaps = generateMaps', | ||
100 | 'window.mapclay = mapclay', | ||
101 | ].join('\n'), | ||
102 | } | ||
103 | } | ||
104 | return null | ||
105 | }, | ||
106 | }) | ||
107 | |||
108 | return config | ||
109 | }) | ||