diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-16 16:57:47 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-16 18:57:18 +0800 |
commit | 1caf56dc0a2bbf4bb484fe4f312b5229a63aace3 (patch) | |
tree | 913a3e5803e9d4128d0ad6d8bd6ed64326d5e5d4 /scripts | |
parent | 9c90bd1cbdc5de5b50def0eb4cb3e65e80194af3 (diff) |
feat: add simple script to test mapclay
* add more options for generateMaps for general purposes
* add rollup config for adding script into addon
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rollup.config.js | 55 |
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' | |||
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,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 | }) | ||