This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
Automatically use appropriate webpack mode based on run/build #94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request changes the default behavior of the webpack bundler to switch it's mode based on if you're running the dev server or building the bundle. I removed the mode line from webpack.config.js, instead either specifying it from the command line (when building), or injecting it into the config object in webpack-dev-server-run.js. Both methods are only used if webpack 4+ is being used. Setting a mode in build.gradle will cause that mode to be used in both cases.
I felt this was a necessary change, as there isn't a simple method of changing webpack's mode based on build type. This seems like a reasonable expected behavior when the plugin is already handling most of webpack's other configuration automatically.
I also pulled the webpack version check out of WebPackBundleTask.kt into it's own class, since it's being used in two places now. The new NpmModuleVersion class can be used to check the major, minor, and patch number of any installed npm module, so I moved it to the npm package. I didn't look through to see if that kind of check was being performed anywhere else in the codebase, but it's there if needed.
testSimpleProjectWebPackBundleWithDce had to be modified to pass, since the output bundle was now being minified. This was causing the last assertion to fail, since "usedFunction2222" was being changed to something shorter. Whatever it's changed to may not be consistent with different versions of webpack or it's minifier, so checking for a certain output would make the test fragile. Instead I just set the test so that webpack runs in development mode, which disables the minifier.