Add support for generating inline sourcemaps #764
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for generating inline sourcemaps with
microbundle --sourcemap inline
.Although usage of inline sourcemaps isn't common, they're handy for debugging purposes in development when including sourcemaps in a separate file isn't an option.
We use microbundle to build Ziggy, and the way most people use the package is to inject our minified script right into their templates. This doesn't require them to build or publish any separate files, but it also means we can't add or publish any files, like sourcemaps. Inlining them would allow us to provide that debugging benefit in development without adding any additional setup from users.
Inlined sourcemaps are base-64 encoded and then included directly in the build output where the source map URL would usually go:
I've also added snapshot tests that confirm everything works correctly. The fixture test package is a copy of the existing
basic
one with a slightly differentpackage.json
.I removed the default
--sourcemap
option oftrue
inprog.js
because it causes the value of this option to always be cast to a boolean, which makes passing'inline'
impossible. If the--sourcemap
option isn't passed it still defaults totrue
, so removing the default value doesn't affect microbundle's behaviour at all.