vite-plugin-yaml
vite-plugin-yaml copied to clipboard
Sourcemap generation
On build, the plugin yields this warning:
[warn] Sourcemap is likely to be incorrect: a plugin (vite:transform-yaml) was used to transform files,
but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
We should add sourcemap generation around the yaml file -> ESM conversion. A potentially useful resource to base this on could be: https://github.com/amireh/yaml-source-map
Found these resources useful:
- https://developer.chrome.com/blog/sourcemaps/#the-anatomy-of-a-source-map
- https://github.com/tctree333/js-yaml-source-map
- Note, this does not generate sourcemaps in the expected browser convention but provides a great resource on generating a sourcemap as
js-yamlparses a file
- Note, this does not generate sourcemaps in the expected browser convention but provides a great resource on generating a sourcemap as
Is there a way to avoid having vite log this warning? I personally don't care about source maps for YAML files but I do care about warnings in the build 😉.
I don't think sourcemaps are useful for this plugin because it outputs JS objects, where there is no way to reference a line back to the source file because JS objects have no concept of a line.
So I think this plugin should somehow indicate back to vite that it will not generate a sourcemap and hopefully that will make vite shut up.
I think the sourcemap would be useful for mapping back through the conversion to which line in the original YAML file is incorrect, however the YAML processor essentially does that already with a well-formatted error displaying exactly which part of the file is causing an issue. Perhaps providing a null-ish source map would satisfy Vite's wants
Of note is that the warning does not originate in vite itself, but in rollup.
Edit: also see https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect
https://github.com/Modyfi/vite-plugin-yaml/pull/9 will suppress the warning until it is figured out how to actually generate a sourcemap.