Skip to content

Add explicit sourceMap option.#23

Merged
gdborton merged 1 commit into
gdborton:masterfrom
Tonkpils:fix-sourcemaps
Jun 30, 2017
Merged

Add explicit sourceMap option.#23
gdborton merged 1 commit into
gdborton:masterfrom
Tonkpils:fix-sourcemaps

Conversation

@Tonkpils
Copy link
Copy Markdown
Contributor

devtools doesn't allow setting some options that the plugins provide. This checks for the currently available source map plugins in the configured plugins to ensure we use the SourceMapSource instead

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-2.004%) to 67.626% when pulling 99a810b on Tonkpils:fix-sourcemaps into 8c410e2 on gdborton:master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-2.004%) to 67.626% when pulling 99a810b on Tonkpils:fix-sourcemaps into 8c410e2 on gdborton:master.

@Tonkpils
Copy link
Copy Markdown
Contributor Author

@gdborton I can try to write some tests for the processAssets function but there's no current coverage on them.

@Tonkpils
Copy link
Copy Markdown
Contributor Author

Tonkpils commented Jun 5, 2017

@gdborton let me know if there's anything I can do to help get this merged!

@gdborton
Copy link
Copy Markdown
Owner

gdborton commented Jun 5, 2017

@Tonkpils Thanks for the PR! Instead of using the names of the constructors could we import webpack and check for actual plugin instances? How do other libs do this detection?

@Tonkpils
Copy link
Copy Markdown
Contributor Author

Tonkpils commented Jun 5, 2017

Instead of using the names of the constructors could we import webpack and check for actual plugin instances?

I'm not sure that comparing two different instances would yield equality. I can test it out and see if it works. We'd also need to bring in webpack as a dependency to pull the plugins out which would require us to specify which versions of webpack are supported though I doubt they would remove/add more sourcemap plugins but it'd still be good to specify it in the package.json.

How do other libs do this detection?

I actually looked around to see what other plugins I could find with similar functionalities but was not able to find something that resembled this. If you have an idea, I'd be happy to take a look at it.

@gdborton
Copy link
Copy Markdown
Owner

gdborton commented Jun 6, 2017

Actually thinking about this further, I don't think this is the correct way to go... By including the plugins individually you're able to provide a test/include/exclude config. https://webpack.js.org/plugins/source-map-dev-tool-plugin/

If we want to check for the presence of the source map plugins we'd also have to track which bundles are not getting filtered through their config.

The best way to go on this might be to include the same sourceMap option that is on the UglifyJSPlugin provided by webpack - https://github.com/webpack-contrib/uglifyjs-webpack-plugin#options

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 7, 2017

Coverage Status

Coverage remained the same at 93.277% when pulling 63ebd59 on Tonkpils:fix-sourcemaps into 61cc65d on gdborton:master.

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 7, 2017

Coverage Status

Coverage remained the same at 93.277% when pulling 787f8b7 on Tonkpils:fix-sourcemaps into 61cc65d on gdborton:master.

@Tonkpils
Copy link
Copy Markdown
Contributor Author

Tonkpils commented Jun 7, 2017

@gdborton I've changed it to your suggestion of using the uglifyJS.sourceMap option and added some tests. Let me know if it looks good, however this would break current functionality of using devtool. We could maintain backwards compatibility by still checking devtool first but it's up to you if you want to to do that.

Let me know and I'll add it back in

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 7, 2017

Coverage Status

Coverage increased (+1.7%) to 94.958% when pulling 4daf419 on Tonkpils:fix-sourcemaps into 61cc65d on gdborton:master.

Comment thread lib/uglifier.js Outdated
function processAssets(compilation, options) {
const assetHash = compilation.assets;
const useSourceMaps = !!compilation.options.devtool;
const useSourceMaps = !!(options.uglifyJS && options.uglifyJS.sourceMap);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this up to the options object? Uglify2 doesn't use this option, and v3 does but it expects an object. I'd like for this to remain a true/false boolean on the options object, that way the uglifyJS object can continue to be passed straight to uglify.

Also, could you add an entry to the README for sourceMap?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll get to it soon 👍

This makes more sense as users may be directly using SourceMap plugins rather
than relying on the devtool setting. User's might also want to enable source
maps for some sections of their code but not others. This change enables them
to do that by using two instances of this plugin.
@gdborton
Copy link
Copy Markdown
Owner

@Tonkpils Thanks for the contribution! I went ahead and altered your commit to move the sourceMap option up, and updated the README. I've got a few more breaking changes in the pipeline, so this won't be released right away.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.7%) to 94.958% when pulling d71676e on Tonkpils:fix-sourcemaps into 79c7115 on gdborton:master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.7%) to 94.958% when pulling d71676e on Tonkpils:fix-sourcemaps into 79c7115 on gdborton:master.

@gdborton gdborton merged commit a12e5f5 into gdborton:master Jun 30, 2017
@gdborton gdborton changed the title Check for source map plugins if devtool is not set Add explicit sourceMap option. Jun 30, 2017
@Tonkpils
Copy link
Copy Markdown
Contributor Author

Thank @gdborton, I had been swamped and wasn't able to give this the attention it deserved. Appreciate you finishing taking over it! 🎉

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.

3 participants