• This repository has been archived on 04/Jun/2024
  • Stars
    star
    621
  • Rank 72,294 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📦 Node.js to browser - The easy way

Lyo

Node.js to browser - The easy way

Npm version Build status Code coverage XO code style

Lyo is the easiest way to transform Node.js modules into browser-compatible libraries.

No decision-making, no configuration needed, it just works!

Lyo uses Browserify, Babel, UglifyJS, and a pinch of magic ✨ so you don't have to worry about configuration

Install & Run

# Install globally
npm 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

<script src="my-module.min.js"></script>
<script>
  myModule('foo');
</script>

Options

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'

Tips

  • Add a .babelrc file at the root of your project to configure 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 from Browserify, Babel or UglifyJS
  • If you like Lyo, you will love lyo.now.sh, an automated bot 🤖 running Lyo on npm modules of your choice

Using Lyo on your own module

Once you've tried Lyo on your module and figured the best options to use, you should consider the following steps

1. Add Lyo to your project

Run lyo init (with options) to edit your package.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

package.json

Don't forget to run npm install after that

2. Add documentation

Run lyo usage (with options) to show an example code snippet. You can edit and include it in your README.md.

$ lyo usage

> Edit and include the following snippet in your README.md

HTML example

3. Commit and publish

Lyo will output a single file called a bundle, by default in a dist folder. You can choose to commit it, or not. It's really up to you.

Run npm 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! 💪

Using Lyo on someone else's module

Sometimes, you stumble upon a npm module without a browser-compatible version.

No worries, just run lyo 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 [email protected] --name Joi

FAQ

What if I need unsupported features?

If you need features unsupported by Lyo (sourcemaps, code splitting...), your best option is not using Lyo, which is nothing more than an all-in-one package, with automatic configuration.

However, if you think Lyo should support this feature, feel free to create a new issue!

Why Lyo when there are thousands of better tools doing the same thing?

Lyo's philosophy is highly inspired from XO, a linter that works immediately, without any configuration. XO is just an ESLint wrapper, but it saves you the hassle of choosing ESLint rules, adding them to a new .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

What does Lyo mean?

Lyo is short for lyophilization, a process that transforms food into a dry and compact form

License

MIT © Boris K

More Repositories

1

chalk-animation

🎬 Colorful animations in terminal output
JavaScript
2,124
star
2

gradient-string

🌈 Beautiful color gradients in terminal output
JavaScript
1,030
star
3

vanity-eth

💎 Browser-based ETH vanity address generator
Vue
730
star
4

rgb-light-card

💡 A Lovelace custom card for RGB lights
JavaScript
414
star
5

nopaste

📋 Client-side paste service
JavaScript
362
star
6

linky

🔌 CLI tool to retrieve Linky smart meters data
TypeScript
216
star
7

ha-linky

📊 Home Assistant add-on for Linky smart meters
TypeScript
187
star
8

home-assistant-extension

📌 Home Assistant browser extension
Vue
169
star
9

git-history-editor

✏️ Online commit editor, intuitive and easy to use
HTML
160
star
10

github-stats-box

📌 Update a gist to contain your GitHub stats
JavaScript
139
star
11

gradient-badge

🍭 Badge generator with color gradient support
JavaScript
70
star
12

i3-config

🐍 A backup of my i3 config
Shell
59
star
13

conso-api

⚡ API for Linky smart meters
Vue
49
star
14

wakatime-to-toggl

📩 Push your WakaTime data to Toggl
JavaScript
35
star
15

linky-cli

⛔️ DEPRECATED - A CLI tool to retrieve your Linky power consumption
JavaScript
19
star
16

stravanity

👟 Easy to beat Strava segments
Vue
17
star
17

ha-history-stats

📈 Statistics about your Home Assistant history
Python
14
star
18

prettier-config

💜 My personal Prettier config & workflow
10
star
19

brackets-gofmt

📑 An extension for Brackets IDE to format Go code.
JavaScript
2
star
20

vanity-eth-cli

Works, but has nothing awesome
Go
1
star
21

blog-comments

1
star
22

bokub

📖 My profile's README
1
star
23

lyo-service

🌄 Lyo builder as a service
JavaScript
1
star