-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
fix terser webpack plugin compatibility #436
Conversation
I didn't update tests, but test is pulling in latest webpack by default. Seeing CIs passing should already prove the new version works with latest webpack without changing fixtures a little bit. |
New behavior:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments, mostly on syntax, a small logical change, happy with this PR overall though.
src/service-worker.js
Outdated
@@ -82,28 +82,28 @@ export default class ServiceWorker { | |||
}; | |||
|
|||
if (this.minify === true) { | |||
if (!UglifyJsPlugin) { | |||
throw new Error('OfflinePlugin: uglifyjs-webpack-plugin is required to preform a minification') | |||
if (!makeUglifyJsPlugin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think makeUglifyJsPlugin !== null
would be more explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to makeUglifyJsPlugin == null
. I think that's what you mean here
src/misc/get-uglify-plugin.js
Outdated
@@ -1,5 +1,11 @@ | |||
const webpack = require('webpack'); | |||
let UglifyJsPlugin; | |||
let isUsingTerser = false; | |||
|
|||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try {
UglifyJsPlugin = require('terser-webpack-plugin');
isUsingTerser = true;
} catch (e) {}
try {
UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
} catch (e) {}
if (!UglifyJsPlugin) {
try {
UglifyJsPlugin = require('uglifyjs-webpack-plugin');
} catch (e) {}
}
Regarding this logic, depending on what optimization libs are present, terser-webpack-plugin
will not be used. For instance, I do not know under what circumstances webpack.optimize.UglifyJsPlugin
will be available, but given the current implementation, terser-webpack-plugin
will have the least presidence, is this correct? Maybe explore a different solution, maybe something like:
try {
UglifyJsPlugin = require('terser-webpack-plugin');
isUsingTerser = true;
if (!UglifyJsPlugin) {
UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
}
if (!UglifyJsPlugin) {
UglifyJsPlugin = require('uglifyjs-webpack-plugin');
}
} catch (e) {}
?
Alternatively, wrap this in a function with early exits. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, you are totally right. Let me fix accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't pull out the try catch blocks, because it was meant for catching exceptions thrown by require
as expected for each require.
@NekR do you have time to check this? Will require a new version and npm deploy! |
@GGAlanSmithee Thank you for the detailed CR. I will address the issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed issues accordingly. Let me know if there's anything else you've got some concerns
src/service-worker.js
Outdated
@@ -82,28 +82,28 @@ export default class ServiceWorker { | |||
}; | |||
|
|||
if (this.minify === true) { | |||
if (!UglifyJsPlugin) { | |||
throw new Error('OfflinePlugin: uglifyjs-webpack-plugin is required to preform a minification') | |||
if (!makeUglifyJsPlugin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to makeUglifyJsPlugin == null
. I think that's what you mean here
src/misc/get-uglify-plugin.js
Outdated
@@ -1,5 +1,11 @@ | |||
const webpack = require('webpack'); | |||
let UglifyJsPlugin; | |||
let isUsingTerser = false; | |||
|
|||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, you are totally right. Let me fix accordingly
src/misc/get-uglify-plugin.js
Outdated
@@ -1,5 +1,11 @@ | |||
const webpack = require('webpack'); | |||
let UglifyJsPlugin; | |||
let isUsingTerser = false; | |||
|
|||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't pull out the try catch blocks, because it was meant for catching exceptions thrown by require
as expected for each require.
ec008d1
to
5f53f09
Compare
it seems CI is failing on the same code that passed before. I don't know why. I will debug soon |
@Bobgy Thanks for your continued work. I see that you reverted your last commit, so I guess there is still something you want to address? Will await further comments from you. |
f57b6c3
to
0529951
Compare
@GGAlanSmithee I made the revert just to retry CI and it was still failing. It seemed that latest webpack was broken at that time. Now I just removed the revert and CI is passing again. Please review if you have time. It seems I messed up a little bit when rebasing. Fixing it right now. |
0529951
to
ad2190c
Compare
OK, all issues fixed and CI is passing again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your continued work on this PR, almost ready to merge this now. I've requested some additional changes, since it's the best time to do these now before this get merged. It's mostly a name change to signify that we might not be using UglifyJsPlugin
, and some minor code change.
If possible, please do these changes. Othervise let me know if you don't have time and I can do a follow-up PR.
Thanks!
@GGAlanSmithee Thank you for your thoughtful comments. |
closes #426