mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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.
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user