Skip to content

Conversation

@caub
Copy link

@caub caub commented Mar 19, 2017

And thanks a lot for this project

@as-com
Copy link
Owner

as-com commented Mar 21, 2017

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
Copy link
Author

caub commented Mar 21, 2017

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
Copy link
Owner

as-com commented Mar 21, 2017

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
Copy link
Author

caub commented Mar 21, 2017

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
Copy link
Author

caub commented Mar 23, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants