diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-11-04 00:20:35 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-11-04 00:20:35 +0800 |
commit | 0151c246004de1c0f3ad944f3da6c70a76a49c7e (patch) | |
tree | 254aef50e1a59b0fb7f84598a83355a632b22038 /scripts | |
parent | 15c85d991530c6eec92597c47012452649b1a503 (diff) |
refactor(build): update build script for addon
* To fit file size limit for addon submission of mozilla.org, add scripts
for each renderers
* add scripts/addon.sh for bundling, with simple rollup commands
* scripts/rollup.config.js no more handle addon build
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/addon.sh | 9 | ||||
-rw-r--r-- | scripts/rollup.config.js | 29 |
2 files changed, 11 insertions, 27 deletions
diff --git a/scripts/addon.sh b/scripts/addon.sh new file mode 100755 index 0000000..3b7bf3b --- /dev/null +++ b/scripts/addon.sh | |||
@@ -0,0 +1,9 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | mkdir -p addon/css | ||
4 | ln -f src/css/dumbymap.css addon/css/dumbymap.css | ||
5 | |||
6 | mkdir -p addon/renderers/ | ||
7 | rollup addon/src/renderers/* --dir addon/renderers | ||
8 | |||
9 | rollup addon/src/dumbymap.mjs --file addon/dumbymap.js | ||
diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js index 547260b..b3a6139 100644 --- a/scripts/rollup.config.js +++ b/scripts/rollup.config.js | |||
@@ -6,7 +6,7 @@ import { join } from 'path' | |||
6 | import { bundleStats } from 'rollup-plugin-bundle-stats' | 6 | import { bundleStats } from 'rollup-plugin-bundle-stats' |
7 | 7 | ||
8 | const prod = process.env.PRODUCTION | 8 | const prod = process.env.PRODUCTION |
9 | const addon = process.env.ADDON | 9 | const watch = process.env.ROLLUP_WATCH |
10 | 10 | ||
11 | function resolve (file, origin) { | 11 | function resolve (file, origin) { |
12 | // Your way to resolve local include path | 12 | // Your way to resolve local include path |
@@ -79,31 +79,6 @@ export default [ | |||
79 | ] | 79 | ] |
80 | .map(config => ({ ...general, ...config })) | 80 | .map(config => ({ ...general, ...config })) |
81 | .filter(config => { | 81 | .filter(config => { |
82 | if (addon) return config.input.match(/dumbymap/) | 82 | if (watch) return config.input.match(/editor/) |
83 | if (!prod) return config.input.match(/editor/) | ||
84 | return true | 83 | return true |
85 | }) | 84 | }) |
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 | 'globalThis.generateMaps = generateMaps', | ||
100 | 'globalThis.mapclay = mapclay', | ||
101 | ].join('\n'), | ||
102 | } | ||
103 | } | ||
104 | return null | ||
105 | }, | ||
106 | }) | ||
107 | |||
108 | return config | ||
109 | }) | ||