esbuild-svelte: Invalid source map if using prepreprocessors
Hello,
I use esbuild with this plugin and I have found the following problem if I enable source map generation with css set to false in compileOptions
const esbuild_svelte = require("esbuild-svelte/configurable")({
compileOptions: { css: false, hydratable: true },
preprocessor: svelteConfig.preprocess,
}
I think the source of the problem is in your code at configurable/index.js line 44:
//if svelte emits css seperately, then store it in a map and import it from the js
if (!compileOptions.css && css.code) {
let cssPath = args.path.replace(".svelte", ".esbuild-svelte-fake-css").replace(/\\/g, "/");
cssCode.set(cssPath, css.code + `/*# sourceMappingURL=${css.map.toUrl()}*/`);
contents = `import "${cssPath}";\n` + contents;
}
If I remove the \n the source map line is ok:
...
contents = `import "${cssPath}";` + contents;
...
I don’t know if this will fix the problem completely. Possibly there is another way in esbuild to inject the css without modifying the contents.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (11 by maintainers)
Commits related to this issue
- Fix sourcemap generation (#13) — committed to EMH333/esbuild-svelte by EMH333 4 years ago
Currently I use:
I can use the current version of esbuild-svelte 0.5.4 without warnings or errors in my test project. I don’t know in which version it fixed my problem because I used an old version of esbuild-svelte in my other project. Now the only problem is still the referenced source in browser is after preprocessing.
See following test project:
Original:
Console.log says:
and is referencing in browser to:
I tested with the branch
preprocessor-sourcemapsand there are the same errors. Not everyjs.map.sourceshas 2 items, but most of them.Here ist my
yarn list | egrep "svelte|esbuild"afteryarn upgrade:Later I will try it with a new project. Now I see no relation between the import statement and the output of one or two items in the
js.map.sourcesarray.I think my current project is too complex for tests. Starting with a new small project hopefully I can discover when the duplication of files happen.