pcb icon indicating copy to clipboard operation
pcb copied to clipboard

Sourcemaps aren't generated when using UglifyJsPlugin

Open nolanlawson opened this issue 8 years ago • 8 comments

Steps to repro:

git clone https://github.com/nolanlawson/test-offline-plugin-sourcemap.git
cd test-offline-plugin-sourcemap
yarn
yarn build

Notice that devtool: 'source-map' and UglifyJsPlugin are enabled, but sw.js doesn't have a sourcemap file:

build/static/js/main.7a5932ac.js
build/static/js/main.7a5932ac.js.map
build/sw.js

To repro this, all I did was use create-react-app, eject it, and then add offline-plugin as one normally would (see this commit).

nolanlawson avatar May 15 '17 21:05 nolanlawson

Hi Nolan! I'm to try to find how to do that with child compilation in webpack, but I do pre-transpile everything on build stage with babel. Is it okay to have sourcemap only from Uglify to generated code by Babel? I don't use source maps actually, so I'm not sure what's best here.

Also, what's that issue with CDN?

NekR avatar May 15 '17 22:05 NekR

I'm not sure; I really don't understand much about how Webpack works. The CDN issue in the other issue is unrelated. :)

Maybe as a workaround, would it be possible to make {minify: false} disable minification even if the UglifyJsPlugin is in use? (Currently {minify: false} seems to be ignored if you use UglifyJsPlugin.) My sw.js file is small enough that I could probably just ship non-minified in production, and that would make it easier to debug.

nolanlawson avatar May 15 '17 22:05 nolanlawson

@nolanlawson it should work actually, minify option is just not released. I know it's in the docs, I just have a bit of a mess with branches/releases at the time. I can release 4.8 with minify option.

I'm looking into how to make it honor source-maps settings. Btw, why do you need source-maps then, are you trying to debug some issue?

NekR avatar May 15 '17 22:05 NekR

Yes, sourcemaps are very useful for debugging, especially in production (it's an open-source project, no worry about revealing source code).

nolanlawson avatar May 15 '17 23:05 nolanlawson

@nolanlawson I don't worry about source code :-) I just wasn't understanding why you needed to debug it until I saw that you're using custom entry. It makes sense now.

NekR avatar May 15 '17 23:05 NekR

Okay, after some research, this is how it should be done:

  • Make sure webpack generated SW assets with source map: use filename/entryname with .js extension, it's hardcoded in webpack
  • After webpack generates source map for the SW bundle, consume both code & source map and generated new ones with offline-plugin header (JSON config at the top of the file) prepended

NekR avatar May 16 '17 05:05 NekR

@nolanlawson I made a release which ships minify option and it's now possible to pass true or false to it (default is still null): https://github.com/NekR/offline-plugin/releases/tag/v4.8.0

NekR avatar May 18 '17 19:05 NekR

@nolanlawson hey, do you think this issue might be resolved with this PR? https://github.com/NekR/offline-plugin/pull/353 @ykzts seems to be working with you on mastodon, so I guess it was an issues for both of you. Please let me know if I can close this one :-)

NekR avatar Mar 08 '18 07:03 NekR