diff --git a/shared/tasks/assets.mjs b/shared/tasks/assets.mjs index b0ca0487cb..20d17063f2 100644 --- a/shared/tasks/assets.mjs +++ b/shared/tasks/assets.mjs @@ -14,15 +14,16 @@ export async function write (filePath, result) { const writeTasks = [] // Files to write + /** @type {SourceMap | undefined} */ + const map = result.map ? JSON.parse(result.map.toString()) : undefined const code = 'css' in result ? result.css : result.code - const map = result.map?.toString() // 1. Write code (example.js) writeTasks.push(writeFile(filePath, code)) // 2. Write source map (example.js.map) if (map) { - writeTasks.push(writeFile(`${filePath}.map`, map)) + writeTasks.push(writeFile(`${filePath}.map`, JSON.stringify(map))) } await Promise.all(writeTasks) @@ -70,3 +71,11 @@ export async function write (filePath, result) { * * @typedef {import('rollup').OutputChunk | import('terser').MinifyOutput | import('postcss').Result} AssetOutput */ + +/** + * Asset source maps + * + * {@link https://github.com/source-map/source-map-spec} + * + * @typedef {import('@jridgewell/source-map').DecodedSourceMap | import('@jridgewell/source-map').EncodedSourceMap} SourceMap + */