Skip to content

Commit

Permalink
Dead code elimination on client
Browse files Browse the repository at this point in the history
Based on #10056
  • Loading branch information
StorytellerCZ committed Feb 4, 2024
1 parent c516ddf commit 2e9d567
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/minifier-js/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ let terser;
const terserMinify = async (source, options, callback) => {
terser = terser || Npm.require("terser");
try {
const result = await terser.minify(source, options);
// Replace Meteor.isServer, Meteor.isClient, Meteor.isDevelopment, Meteor.isProduction with true or false
// so that terser can remove the dead code in the appropriate scenario
const cleanSource = source.replace(/\b(Meteor\.isServer|Meteor\.isDevelopment|process\.env\.NODE_DEBUG)\b/g, 'UGLIFYJS_FALSE')
.replace(/\b(Meteor\.isClient|Meteor\.isProduction)\b/g, 'UGLIFYJS_TRUE');
const result = await terser.minify(cleanSource, options);
callback(null, result);
return result;
} catch (e) {
Expand All @@ -24,7 +28,9 @@ export const meteorJsMinify = function (source) {
dead_code: true, // remove unreachable code
typeofs: false, // set to false due to known issues in IE10
global_defs: {
"process.env.NODE_ENV": NODE_ENV
"process.env.NODE_ENV": NODE_ENV,
UGLIFYJS_FALSE: false,
UGLIFYJS_TRUE: true
}
},
// Fix issue #9866, as explained in this comment:
Expand Down

0 comments on commit 2e9d567

Please sign in to comment.