Sourcemaps aren't generated when using UglifyJsPlugin
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).
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?
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 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?
Yes, sourcemaps are very useful for debugging, especially in production (it's an open-source project, no worry about revealing source code).
@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.
Okay, after some research, this is how it should be done:
- Make sure webpack generated SW assets with source map: use filename/entryname with
.jsextension, 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-pluginheader (JSON config at the top of the file) prepended
@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
@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 :-)