as-com / mozjpeg-js

Implementation of MozJPEG in pure JavaScript, using Emscripten
https://andrewsun.com/projects/mozjpeg-js/
BSD 3-Clause "New" or "Revised" License
27 stars 6 forks source link

add demo #2

Open caub opened 7 years ago

caub commented 7 years ago

And thanks a lot for this project

as-com commented 7 years ago

Sorry about the delay - I've been quite busy over the past few days.

I noticed that you modified lib/cjpeg.js. That file is a CommonJS module, meant to be used by Node.js. To use it in a browser, you'll need to bundle it correctly, which is done in the NPM package: https://unpkg.com/mozjpeg-js@3.1.0-beta.1/dist/mozjpeg.js

Thanks for your contribution! I'll probably reuse your code once I get a chance to create a demo page (and properly document this library).

caub commented 7 years ago

Thanks, yes I know cjpeg.js was meant to be required and felt bad to modify it, but I use mozjpeg-js or pngquantjs from a Worker in browser, doesn't really need to be integrated in some other code, a global function is enough I think. Do you accept if I put a if (typeof module!=='undefined') .. in cjpeg.js instead to keep compatibilty?

function mozjpeg(..){...}; if (typeof module!='undefined'){ module.exports = mozjpeg; } in the build script if I managed to (I'm on windows)

as-com commented 7 years ago

That's already done in the bundled version. The Rollup build process automatically creates a module that, if running in a browser, creates a global function mozjpeg.cjpeg.

caub commented 7 years ago

and the bundle comes with npm run build right, I had and still have this error:

D:\Dev\mozjpeg-js>npm run build

> mozjpeg-js@3.1.0-beta.1 build D:\Dev\mozjpeg-js
> rollup -c

Could not load null: path must be a string or Buffer
Error: Could not load null: path must be a string or Buffer
    at D:\Dev\mozjpeg-js\node_modules\rollup\src\Bundle.js:183:11
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:422:7)
    at startup (bootstrap_node.js:143:9)
    at bootstrap_node.js:537:3
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\admin\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v7.6.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! mozjpeg-js@3.1.0-beta.1 build: `rollup -c`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mozjpeg-js@3.1.0-beta.1 build script 'rollup -c'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mozjpeg-js package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     rollup -c
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs mozjpeg-js
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls mozjpeg-js
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\Dev\mozjpeg-js\npm-debug.log
caub commented 7 years ago

the problem is probably that index.js is in lib/ it should be at the root

Ok fixed now, dist/mozjpeg.js is uningnored, because I need it to use it from the browser