tinyify icon indicating copy to clipboard operation
tinyify copied to clipboard

Empty output file

Open mig82 opened this issue 5 years ago • 3 comments

I'm having issues trying to get this to generate a minified output file. The mentioned output file is empty. I've tried these options. None work.

browserify -p tinyify src/main.js > foobar.min.js
browserify -p tinyify src/main.js -o foobar.min.js
browserify -p tinyify -o foobar.min.js src/main.js
browserify src/main.js -p tinyify -o foobar.min.js

And they all result in an empty foobar.min.js file. What am I doing wrong?

mig82 avatar Jan 28 '20 10:01 mig82

How does src/main.js look like?

Sometimes modules don't have side effects. Like if they're just doing:

function initApp () {
  // stuff here
}
module.exports = initApp

tinyify would consider all of this unused code and remove this. To check if this is what happening, try adding a --standalone/-s flag to the browserify command, because then the export would not be considered unused.

browserify -p tinyify -s MyApp src/main.js > foobar.min.js

goto-bus-stop avatar Jan 28 '20 11:01 goto-bus-stop

Thank you @goto-bus-stop. That did the trick. Except it then defines the resulting lib as a UMD. I'd like a way to stop Tinyify from removing dead code. But apparently there's no flag for this in this plugin.

mig82 avatar Jan 29 '20 13:01 mig82

If you do window.MyApp = initApp in your main file it should also work.

goto-bus-stop avatar Feb 24 '20 13:02 goto-bus-stop