diff --git a/README.md b/README.md index 599cb78..be80168 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ This plugin takes an [import map](https://github.com/WICG/import-maps) as option | path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. | | urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. | | maps | `[]` | `array` | `false` | Array of import map as objects. | +| base | `` | `string` | `false` | Base URL to be applied when parsing the import map. | ## Note on the rollup external option diff --git a/package.json b/package.json index e823b42..0ea1f1e 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,6 @@ "dependencies": { "@eik/common": "3.0.1", "undici": "5.12.0", - "rollup-plugin-import-map": "3.0.0" + "rollup-plugin-import-map": "4.0.0-next.1" } } diff --git a/src/plugin.js b/src/plugin.js index 1d03bf1..caea10d 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -29,10 +29,11 @@ const fetchImportMaps = async (urls = []) => { } }; -export default function esmImportToUrl({ +export default function eikPlugin({ path = process.cwd(), maps = [], urls = [], + base = '', } = {}) { const pMaps = Array.isArray(maps) ? maps : [maps]; const pUrls = Array.isArray(urls) ? urls : [urls]; @@ -48,7 +49,9 @@ export default function esmImportToUrl({ // Fetch import maps from the server const fetched = await fetchImportMaps([...config.map, ...pUrls]); - plugin = importMapPlugin([...fetched, ...pMaps]); + const pBase = (base === '') ? config.server : base; + + plugin = importMapPlugin(pBase, [...fetched, ...pMaps]); await plugin.buildStart(options); }, diff --git a/test/plugin.js b/test/plugin.js index da2c27b..53ded27 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -46,6 +46,7 @@ tap.test('plugin() - import map fetched from a URL', async (t) => { }, }], urls: [`${address}/one`, `${address}/two`], + base: 'https://cdn.eik.dev', })], };