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

Sourcemaps broken when using fingerprinting #265

Closed
mike-engel opened this issue Apr 15, 2021 · 0 comments · Fixed by #266
Closed

Sourcemaps broken when using fingerprinting #265

mike-engel opened this issue Apr 15, 2021 · 0 comments · Fixed by #266

Comments

@mike-engel
Copy link
Contributor

We've run into an issue when using ember-cli-terser and fingerprinting when building for production (or, when both are enabled). After a bit of debugging, I've nailed it down to the order that ember-cli-terser (and thus brocolli-terser-sourcemap) and broccoli-asset-rev run.

Background

Our app is written with both typescript and javascript, so the typescript compiler first compiles and creates sourcemaps for all the files, then babel runs and consumes those sourcemaps and updates them for the generated code. Then when terser runs, it consumes those sourcemaps and updates it for the minified code. Up to this point, everything works perfectly. Using source-map, I can verify that a line in the minified file correctly points to the right line and column in the original typescript file.

The problem comes right after, when broccoli-asset-rev runs. We use it to fingerprint and prepend our CDN url to assets, which changes the column of code in the minified javascript file, but doesn't update the sourcemap. This leads to a case where the line/column combination in the minified, fingerprinted file, no longer match up to the source.

Validation

I've tested this theory by turning off fingerprinting and source maps then work as expected. Additionally, if I disable ember-cli-terser but leave fingerprinting enabled, source maps also work ok. This is because the asset URL changes don't affect the column/line count of the code following it, because it's not minified and all on one line.

Source

Ultimately, I believe the source of the issue is the declaration that ember-cli-terser run before broccoli-asset-rev in the package.json config. This has been the case since v1.0.1.

Resolution

I'm not sure if there was a root reason for making ember-cli-uglify run before ember-asset-rev, but I believe it should be set to after. During my testing, I found that switching from before to after still compiles fingerprinted assets correctly, but also maintains the integrity of sourcemaps.

I hope that all made sense, and if you have questions I'd be happy to try and answer them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant