From 64c75141871ff5f87097efd6580f7fdbffca2800 Mon Sep 17 00:00:00 2001 From: italo jose Date: Tue, 6 May 2025 15:16:00 -0300 Subject: [PATCH] feat: enhance minification process with configuration retrieval and SWC integration - Added a function to read the Meteor project's package.json for configuration settings. - Updated the minifier to utilize the new SWC integration, replacing the previous dependency. - Introduced a constructor in the MeteorMinifier class to store configuration for use during minification. - Added TODO comments for future enhancements regarding file skipping and build option checks. --- packages/standard-minifier-js/package.js | 1 + .../standard-minifier-js/plugin/minify-js.js | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/standard-minifier-js/package.js b/packages/standard-minifier-js/package.js index 6a8e2b9569..05c699ddb1 100644 --- a/packages/standard-minifier-js/package.js +++ b/packages/standard-minifier-js/package.js @@ -17,6 +17,7 @@ Package.registerBuildPlugin({ "@babel/runtime": "7.18.9", '@babel/parser': '7.22.7', 'terser': '5.19.2', + '@meteorjs/reify': '0.25.4', }, sources: [ 'plugin/minify-js.js', diff --git a/packages/standard-minifier-js/plugin/minify-js.js b/packages/standard-minifier-js/plugin/minify-js.js index 144e498121..527279b383 100644 --- a/packages/standard-minifier-js/plugin/minify-js.js +++ b/packages/standard-minifier-js/plugin/minify-js.js @@ -1,6 +1,13 @@ import { extractModuleSizesTree } from "./stats.js"; import CombinedFile from "./comibinedFile.js"; +function getConfig() { + // read the meteor project pakcgae.json file + const packageJson = fs.readFileSync(`${getMeteorAppDir()}/package.json`, 'utf8'); + const meteorConfig = JSON.parse(packageJson).meteor; + return meteorConfig; +}; + const statsEnabled = process.env.DISABLE_CLIENT_STATS !== 'true' if (typeof Profile === 'undefined') { @@ -29,11 +36,14 @@ Plugin.registerMinifier({ class MeteorMinifier { - _minifyWithSwc(file) { - process.stdout.write('minifyWithSwc...\n'); - swc = swc || require('meteor-package-install-swc'); - const NODE_ENV = process.env.NODE_ENV || 'development'; + constructor() { + this.config = getConfig(); + } + _minifyWithSWC(file) { + swc = swc || require('@meteorjs/swc-core'); + const NODE_ENV = process.env.NODE_ENV || 'development'; + let map = file.getSourceMap(); let content = file.getContentsAsString(); @@ -89,8 +99,12 @@ class MeteorMinifier { } minifyOneFile(file) { + // TODO: create a function to check if the file should be skipped and share it with babel-compiler.js file + if(this.config.modernTranspiler) return this._minifyWithTerser(file).await(); + // TODO: read the pkg.json file from the meteor project and ceck the swc build option + // TODO: add a flag to the minifier to use swc or terser inside the meteor project package.json try { - return this._minifyWithSwc(file); + return this._minifyWithSWC(file); } catch (swcError) { try { // swc always parses as if the file is a module, which is