-
Notifications
You must be signed in to change notification settings - Fork 884
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
Add custom webpack loader to remove unused mimetypes from mime-db #5148
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* electron-context-menu only needs mime-db for its save as feature. | ||
* As we only activate save image and save as image features, we can remove all other mimetypes, | ||
* as they will never get used. | ||
* Which results in quite a significant reduction in file size. | ||
* @param {string} source | ||
*/ | ||
module.exports = function (source) { | ||
const original = JSON.parse(source) | ||
|
||
const reduced = {} | ||
|
||
for (const mimeType of Object.keys(original)) { | ||
if (mimeType.startsWith('image/') && original[mimeType].extensions && | ||
(!mimeType.startsWith('image/x-') || mimeType === 'image/x-icon' || mimeType === 'image/x-ms-bmp') && | ||
(!mimeType.startsWith('image/vnd.') || mimeType === 'image/vnd.microsoft.icon')) { | ||
|
||
// Only the extensions field is needed, see: https://github.com/kevva/ext-list/blob/v2.2.2/index.js | ||
reduced[mimeType] = { | ||
extensions: original[mimeType].extensions | ||
} | ||
} | ||
} | ||
|
||
return JSON.stringify(reduced) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Just make it easier to read
Coz the logic seems to be
image/
MIME types not matching specific prefixes with extensionsThere 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.
Current code is easier to read imo
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 agree with @efb4f5ff-1298-471a-8973-3d47447115dc I think the current code is more readable, also your code changes the logic, resulting in a different output.
I prefer the or/
||
operator over writing lots of single line ifs that have the same outcome, as to me it's a lot more readable, especially when the variable names are short.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 agree with @efb4f5ff-1298-471a-8973-3d47447115dc I think the current code is more readable, also your code changes the logic, resulting in a different output.
I prefer the or/
||
operator over writing lots of single line ifs that have the same outcome, as to me it's a lot more readable, especially when the variable names are short.Also we really don't need to check for
null
here, as this code runs on a json file with a known structure so the only options are non-existent/undefined
or an array, so checking for loose equality withnull
is rather confusing. Also the truthy check already covers bothundefined
andnull
.