matthiasmullie / minify

CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.
https://matthiasmullie.github.io/minify/
MIT License
1.96k stars 310 forks source link

Incorrect export handling #420

Open K0stka opened 7 months ago

K0stka commented 7 months ago

Version (from my composer.json file): "matthiasmullie/minify": "^1.3"

In my project, I have multiple JS files, that each do their own thing. I then use this library to minify them at runtime and in order to have proper type-checking I need to use import/export statements. However, the problem is that this library treats them just as if they were just normal pieces of the code.

Example: file a.js

function foo(bar) {
  ...
} 
export foo;

file b.js

import foo from "./a"
const foobaz = foo("baz");
export foobaz;

The ideal output of this would be (not minified for readability):

function foo(bar) {
  ...
}
const foobaz = foo("baz");
export { foo, foobaz };

I.e. omitting the import statement because it isn't necessary and moving + combining the export at the bottom of the bundle.

However, this library simply minifies the files and combines them.

Have I missed anything?

Edit: Thinking about it, even just removing the import/export statements alltogether would probably solve the issue, because this way we don't have to worry about what path are we importing from ect. and browsers don't really care about this if you are smart about naming things.