From 1caf56dc0a2bbf4bb484fe4f312b5229a63aace3 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 16 Oct 2024 16:57:47 +0800 Subject: feat: add simple script to test mapclay * add more options for generateMaps for general purposes * add rollup config for adding script into addon --- scripts/rollup.config.js | 55 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'scripts') 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' import { join } from 'path' import { bundleStats } from 'rollup-plugin-bundle-stats' -const production = !process.env.ROLLUP_WATCH +const prod = process.env.PRODUCTION +const addon = process.env.ADDON + +function resolve (file, origin) { + // Your way to resolve local include path +} + +function pathResolve (options) { + return { + resolveId: function (file, origin) { + // Your local include path must either starts with `./` or `../` + if (file.startsWith('./') || file.startsWith('../')) { + // Return an absolute include path + return resolve(file, origin) + } + return null // Continue to the next plugins! + }, + } +} const general = { output: [ @@ -13,7 +31,6 @@ const general = { dir: './dist', format: 'esm', entryFileNames: '[name].mjs', - sourcemap: 'true', }, ], watch: { @@ -42,12 +59,13 @@ const general = { return null }, }, + pathResolve(), node(), commonjs(), - production && terser({ + prod && terser({ keep_fnames: true, }), - production && bundleStats(), + prod && bundleStats(), ], } @@ -60,4 +78,31 @@ export default [ }, ] .map(config => ({ ...general, ...config })) - .filter((config) => production || config.input.match(/editor/)) + .filter(config => { + if (addon) return config.input.match(/dumbymap/) + if (!prod) return config.input.match(/editor/) + }) + .map(config => { + if (!addon) return config + + config.output.forEach(o => o.dir = './addon') + config.plugins.push({ + name: 'remove-exports', + transform (code, id) { + if (id.includes(config.input)) { + // remove export keyword for addon + const transformedCode = code.replace(/\n(\s*)export\s*/g, '$1') + return { + code: [ + transformedCode, + 'window.generateMaps = generateMaps', + 'window.mapclay = mapclay', + ].join('\n'), + } + } + return null + }, + }) + + return config + }) -- cgit v1.2.3-70-g09d2