diff --git a/.changeset/healthy-shrimps-hope.md b/.changeset/healthy-shrimps-hope.md new file mode 100644 index 000000000..c96f7b3d0 --- /dev/null +++ b/.changeset/healthy-shrimps-hope.md @@ -0,0 +1,5 @@ +--- +'wmr': patch +--- + +Handle JSON string source maps returned from rollup plugins diff --git a/packages/wmr/src/lib/rollup-plugin-container.js b/packages/wmr/src/lib/rollup-plugin-container.js index dcf1e8df8..8cfe92372 100644 --- a/packages/wmr/src/lib/rollup-plugin-container.js +++ b/packages/wmr/src/lib/rollup-plugin-container.js @@ -290,6 +290,18 @@ export function createPluginContainer(plugins, opts = {}) { logTransform(`${kl.dim(formatPath(id))} [${plugin.name}]`); if (typeof result === 'object') { + if (typeof result.map === 'string') { + try { + result.map = JSON.parse(result.map); + } catch { + if (hasDebugFlag()) { + logTransform(kl.yellow(`Invalid source map JSON returned by plugin `) + kl.magenta(plugin.name)); + } + + result.map = undefined; + } + } + if (result.map) { // Normalize source map sources URLs for the browser result.map.sources = result.map.sources.map(s => {