Giter Site home page Giter Site logo

sorvor's Introduction

sørvør

lightning fast, zero config build tool for modern Javascript and Typescript.

Introduction

sørvør is a lightweight replacement for heavier, more complex build tools such as webpack or parcel. It is an opinionated take on esbuild with sane default and plugins to enhance your development workflow.

Major Features

  • Instant Startup: sørvør is authored in golang, which offers the best startup time for command line applications. Often times, sørvør will finish bundling your project by the time a node.js bundler starts loading.
  • Easy Installation: sørvør is distributed as a single binary for all major platforms. It's just one command to install sørvør using installation method of your choice.
  • Optimize for Production: Build for production with built-in optimizations and Asset Pipeline.

Installation

The easiest method to install sørvør is using npm or yarn:

npm install sorvor
# or
yarn add sorvor

Alternatively, if you have go installed, use go get to install sørvør:

go get github.com/osdevisnot/sorvor

Once installed, verify your installation using version flag

sorvor --version

Quickstart

You can always refer example projects for fully integrated setup using sørvør. To get started, let's set up a simple Preact application using sørvør. First, create a minimal scaffold using degit:

npx degit osdevisnot/sorvor-minimal preact-hello

The minimal scaffold comes with a README.md file with short description of available commands. Let's start the live reloading server using the command from README.md:

sorvor --serve

This should bundle your project and start a live reloading server at http://localhost:1234.

Now, let's add a simple Preact Component which renders Hello World.

import { h, render } from "preact";

const Counter = () => <div>Hello World</div>;

render(<Counter />, document.body);

You should notice an error on terminal which should look like this:

2021/02/23 09:55:58 Warn: Unexpected "<"

This error indicates sørvør was unable to parse JSX syntax we just entered. Let's restart sørvør to be able to parse JSX Syntax:

sorvor --serve --loader:.js=jsx --jsx-factory=h

On restart, your browser should display Hello World rendered using preact.

Node.js Usage

You can use sørvør to bundle browser based applications, but it is equally suitable for node.js applications as well. Let's try to build a simple express server using sørvør as build tool.

First of, create a project directory and install express as a dependency:

mkdir hello-server
cd hello-server
npm init --yes
npm install express

Now, let's create a server.js file in src directory, and paste below code in it:

import express from "express";

const app = express();
const port = 3000;

app.get("/", (req, res) => {
  res.send("Hello World !!");
});

app.listen(port, () => {
  console.log(`App Ready on http://localhost:${port}`);
});

Now, let's start the build using

sorvor src/server.js --serve --platform=node

The platform node automatically adds all the dependencies from package.json as external. The serve when combined with node platform, builds the entry file and starts running it once the build is complete. Try visiting http://localhost:3000 to see "Hello World" rendered in the browser.

Asset Pipeline

The asset pipeline for sørvør is partially inspired by HUGO pipes. To use the asset pipeline, use below annotations in your HTML entrypoint.

Live Reload

sørvør supports live reloading connected browsers based on SSE Web API.

To use this feature, include the livereload annotation in your HTML entrypoint like this:

<html>
  ...
  <body>
    {{ livereload }}
  </body>
  ...
</html>

Bundle with esbuild

To run an entrypoint through esbuild, use esbuild annotation in your HTML entrypoint like this:

<script type="module" src="{{ esbuild "index.js" }}"></script>

Copy static files

To copy a file from source to outdir, use copy annotation in your HTML entrypoint like this:

<link rel="shortcut icon" href='{{ copy "assets/favicon.ico" }}' type="image/x-icon" />

Plugins

sørvør enhances esbuild with few quality of life plugins. These plugins are enabled by default and require no configuration for usage.

env plugin

The env plugin imports the current environment variables at build time. You can use the environment variables like this:

import { PATH } from "env";
console.log(`PATH is ${PATH}`);

Configuration

For most part, sørvør tries to use sensible defaults, but you can configure the behaviour using command line arguments below:

cli argument description default value
--host=... host for sørvør localhost
--port=... port for sørvør 1234
--serve enable development mode false
--secure use https with localhost false

sørvør forwards all the other command line arguments to esbuild.

--secure automatically creates a self-signed certificate for provided host.

to disable chrome warnings, open chrome://flags/#allow-insecure-localhost and change the setting to "Enabled".

Please refer documentation for simple esbuild options or advance options to further customize the bundling process.

sørvør configures below values for esbuild as defaults which you can override using command line arguments:

cli argument description default value
--outdir=... target directory for esbuild output dist

sørvør configures below values for esbuild which can not be changed:

cli argument description default value
--bundle enables bundling output files true
--write enables writing built output to disk true
--define value for process.env.NODE_ENV production and development with --serve

Inspirations

This project is inspired by servør from Luke Jackson, which provides similar zero dependency development experience but lacks integration with a bundler/build tools.

License

sørvør is licensed under the MIT License.

Documentation is licensed under Creative Commons License.

Created with ❤️ by @osdevisnot and all contributors.

sorvor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sorvor's Issues

[ROADMAP] Plugin architecture in the works?

Background on this issue

  1. I'm very appreciative of sørvør & am finding it very promising/useful. I've tried:
    • @web/dev-server + esbuild
    • esbuild --server
      ...neither worked with my prototypical codebase. sørvør, despite being written in a different language than my project, worked right out of the box. I especially appreciate the ability to pass through any arguments to esbuild—an ability that many projects neglect
  2. Being able to use directives in html immediately made me think of a potential plugin architecture. In digging into the sørvør source I came across this block of code—that looks like an ideal place to pull in custom directives (e.g. hmr or workbox/ServiceWorker)

Question

With that background:
Are you working toward a plugin architecture / opportunity for extensibility?
The ability to add the aforementioned capabilities (perhaps w/ the ability to intercept HTML requests) would round out sørvør's viability for my team's use case. I've not done production Go language programming yet but I intend to pick it up in order to contribute... & I wan't to see if that work could be done within sørvør or would need to be done on top of it

Sorvor not recognized as internal nor external command

I added sorvor to a project with npm, be it global or local it doesn't work.

In my package.json, I call it with npm run dev.
"dev": "sorvor src/tool/server.js --serve --platform=node --loader:.js=jsx",

I'm using Git bash on windows

Support for esbuild plugins

Hello,

Thank you for this project, it's very promising!

I'm working on a project has a number of SVG imports, and in the current webpack setup they are imported as SVGR:

import Prev2 from '../img/Prev2.svg';
import Prev from '../img/Prev.svg';
import Next2 from '../img/Next2.svg';
import Next from '../img/Next.svg';

esbuild does not support SVGs natively, however, there is a plugin for this: https://github.com/kazijawad/esbuild-plugin-svgr

Unfortunately, plugins cannot be configured through the esbuild CLI, and must be specified be specified in JavaScript or Go: evanw/esbuild#111 (comment).

Is there a way I could use the SVGR plugin via sørvør?

Thanks!

Svelte TypeScript example

This is exactly the project I was hoping to see. Really hope it takes off 🙌

It isn't immediately clear how to use it to bundle a Svelte app. Would you be able to add an example?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.