GithubHelp home page GithubHelp logo

yjl9903 / presea Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 1.0 524 KB

An utility function for bundling Node.js single executable applications.

Home Page: https://www.npmjs.com/package/presea

License: MIT License

JavaScript 1.35% TypeScript 98.65%
nodejs single-executable unbuild ncc

presea's Introduction

presea

version CI

An utility function for bundling Node.js single executable applications.

From Node.js 20, it supports Single Executable Applications experimentally. This package integrates the binary bundle steps with unbuild following Single executable applications | Node.js v20.0.0 Document.

Installation

npm i -D presea

Usage

import { bundle } from 'presea'

await bundle('path/to/package')

CLI

This is working in progress.

npm i -g presea

echo "console.log('Hello')" > cli.js

presea cli.js

GitHub Actions

Here is an example GitHub Actions config to bundle single executable applications.

You should replace <bin> to your own binary name which is the same as your package.json or your build config.

name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  bundle:
    name: Bundle on ${{ matrix.target }}

    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - target: linux
            os: ubuntu-latest
            binary: ./dist/<bin>
          - target: windows
            os: windows-latest
            binary: .\dist\<bin>.exe

    steps:
      - uses: actions/checkout@v3

      - name: Setup pnpm
        uses: pnpm/[email protected]

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: 20.x
          cache: pnpm

      - name: Install
        run: pnpm install

      - name: Build
        run: pnpm build  # now binary is located at matrix.binary

      # Upload to release and so on...

unbuild

Warning

Currently, SEA only supports for a single script, and can not require other node_modules.

But unbuild can not bundle the whole project into a single script.

See feat: unbuild bundle into a single script.

You should provide field bin in your package.json like the following config.

{
  "bin": {
    "hello": "./dist/hello.mjs"
  }
}

Import presea preset in your build.config.ts.

// build.config.ts

import { defineBuildConfig } from 'unbuild';

import { Sea } from 'presea/unbuild';

export default defineBuildConfig({
  preset: Sea(),
  // Your config...
});

Then, just run unbuild and the bundled single executable application is in your output directory.

$ npx unbuild

$ ./dist/hello world
Hello, world!

Development

  • Clone this repository
  • Use pnpm as the package manager (npm i -g pnpm)
  • Install dependencies using pnpm install
  • Build the module using pnpm build or stub the module using pnpm dev
  • Test the bundle using cd example && pnpm i && pnpm build

License

MIT License © 2023 XLor

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.