Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating inline sourcemaps #764

Merged
merged 7 commits into from
Dec 18, 2020
Merged

Add support for generating inline sourcemaps #764

merged 7 commits into from
Dec 18, 2020

Conversation

bakerkretzmar
Copy link
Contributor

@bakerkretzmar bakerkretzmar commented Dec 12, 2020

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:

var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};export default function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAuZXNtLmpzIiwic291cmNlcyI6WyIuLi9zcmMvdHdvLmpzIiwiLi4vc3JjL2luZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBhc3luYyBmdW5jdGlvbiB0d28oLi4uYXJncykge1xuXHRyZXR1cm4gYXJncy5yZWR1Y2UoKHRvdGFsLCB2YWx1ZSkgPT4gdG90YWwgKyB2YWx1ZSwgMCk7XG59XG4iLCJpbXBvcnQgeyB0d28gfSBmcm9tICcuL3R3byc7XG5cbmV4cG9ydCBkZWZhdWx0IGFzeW5jIGZ1bmN0aW9uKC4uLmFyZ3MpIHtcblx0cmV0dXJuIFthd2FpdCB0d28oLi4uYXJncyksIGF3YWl0IHR3byguLi5hcmdzKV07XG59XG4iXSwibmFtZXMiOlsidHdvIiwicmVkdWNlIiwidG90YWwiLCJ2YWx1ZSIsImFyZ3MiXSwibWFwcGluZ3MiOiJJQUFzQkEsaUNBQ3JCLHVCQUFPLGlCQUFLQyxPQUFPLFNBQUNDLEVBQU9DLFVBQVVELEVBQVFDLEdBQU8sSUFEckQsa0ZDRWlDQywwQ0FDbEJKLGVBQU9JLDRDQUFhSixlQUFPSSxxQkFBekMsTUFBTyxVQURSIn0=

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 different package.json.

I removed the default --sourcemap option of true in prog.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 to true, so removing the default value doesn't affect microbundle's behaviour at all.

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2020

🦋 Changeset detected

Latest commit: f152b7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
microbundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

src/index.js Outdated Show resolved Hide resolved
@developit developit merged commit fdafaf7 into developit:master Dec 18, 2020
@preact-bot preact-bot mentioned this pull request Dec 18, 2020
@bakerkretzmar bakerkretzmar deleted the inline-sourcemaps branch December 18, 2020 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants