- Notifications
You must be signed in to change notification settings - Fork21
📦 Node.js to browser - The easy way
License
bokub/lyo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Node.js to browser - The easy way
Lyo is the easiest way to transform Node.js modules into browser-compatible libraries.
No decision-making, no configuration needed, it just works!
Lyo usesBrowserify,Babel,UglifyJS, and a pinch of magic ✨ so you don't have toworry about configuration
# Install globallynpm i -g lyo# Run (on your own module)lyo# Run (on any npm module)lyo get<module>
Lyo will create a single.min.js
file that you can import in a<script>
tag
<scriptsrc="my-module.min.js"></script><script>myModule('foo');</script>
Lyo is supposed to work right away, but you can force things with some options if needed.
$ lyo --help Usage $ lyo [options] Run Lyo $ lyo init [options] Add Lyo to your project $ lyo usage [options] Show how to use the output file $ lyo get <module> [options] Run Lyo on a module from npm Options --input -i Entry file --output -o Output file / folder --name -n Module name in browser --banner -b Add a banner to the top of the bundle Examples $ lyo $ lyo -i main.js $ lyo -n runFunction $ lyo get query-string $ lyo -o dist/bundle.min.js $ lyo -b 'Lyo\nLicensed under MIT'
- Add a
.babelrc
file at the root of your project toconfigure the Babel compilation step - The bundle is supposed to run in browsers. A bundle used in a Node.js program will probably be slower than the original module
- Don't blame Lyo if it fails to compile your code. The error could come fromBrowserify,Babel orUglifyJS
- If you like Lyo, you will lovelyo.now.sh, an automated bot 🤖 running Lyo on npm modules of your choice
Once you've tried Lyo on your module and figured the best options to use, you should consider the following steps
Runlyo init
(with options) to edit yourpackage.json
as follows:
- Lyo will be added to the dev dependencies
- A pre-publish script will be created (or edited) so Lyo is triggered before every
npm publish
- If you provide options,they will be saved as default options
# Example with some random options$ lyo init -i lib/main.js -n runMyModule
Don't forget to runnpm install
after that
Runlyo usage
(with options) to show an example code snippet. You can edit and include it in yourREADME.md
.
$ lyo usage> Edit and include the following snippet in your README.md
Lyo will output a single file called abundle, by default in adist
folder. You can choose to commit it, or not.It's really up to you.
Runnpm publish
, Lyo will compile your module, and the bundle will be pushed to the npm registry with the rest of your module.Congratulations, you're done! 💪
Sometimes, you stumble upon a npm module without a browser-compatible version.
No worries, just runlyo get <module>
to download and compile it right away ⚡
# Compile query-string (npmjs.com/package/query-string)$ lyo get query-string# Compile a specific version of Joi (npmjs.com/package/joi)$ lyo get joi@13.5.0 --name Joi
If you need features unsupported by Lyo (sourcemaps, code splitting...), your best option is not using Lyo, which isnothing more than an all-in-one package, with automatic configuration.
However, if you think Lyo should support this feature, feel free to create a newissue!
Lyo's philosophy is highly inspired fromXO, a linter that works immediately, without anyconfiguration. XO is just an ESLint wrapper, but it saves you the hassle of choosing ESLint rules, adding them to anew.eslintrc
file, installing plugins...
I use XO for almost all my projects, but I could not find any tool as simple as XO for Node.js > browser compilation.That's why I created Lyo
Lyo is short forlyophilization, a process that transforms foodinto a dry and compact form
MIT ©Boris K
About
📦 Node.js to browser - The easy way