npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

esbuild-plugin-serverless

v1.0.1

Published

[![Node version](https://img.shields.io/npm/v/esbuild-plugin-serverless.svg?style=flat)](https://www.npmjs.com/package/esbuild-plugin-serverless) \ This plugin allows you to imitate [hot-module-replacement](https://webpack.js.org/guides/hot-module-replace

Downloads

25

Readme

Esbuild Serverless Plugin

Node version
This plugin allows you to imitate hot-module-replacement when working with NodeJS based Cloud Functions in Yandex Cloud.
Using esbuild it rebuilds the code on save and deploys it to the cloud without even saving compiled files to the disk

Setup

Install the neccessary packages

npm install esbuild esbuild-plugin-serverless ts-node

Create a file with a name similar to build.ts

Describe your Cloud Functions entrypoints and pass them to esbuild build function.

import {
  EntrypointConfig,
  Entrypoints,
  getFromEnv,
  esbuildServerlessPlugin
} from 'esbuild-plugin-serverless'

const common: EntrypointConfig = {
  runtime: 'nodejs16',
  tag: ['latest'],
  resources: {
    $type: 'yandex.cloud.serverless.functions.v1.Resources',
    memory: 128 * 1024 * 1024
  },
  executionTimeout: {
    $type: 'google.protobuf.Duration',
    seconds: 5,
    nanos: 0
  }
}

const entrypoints: Entrypoints = {
  index: () => ({
    ...common,
    functionId: getFromEnv('CLOUD_FUNCTION_ID'),
    entrypoint: 'index.handler'
  })
}

import { context as createContext } from 'esbuild'
import esbuildServerlessPlugin from 'esbuild-plugin-serverless'
import { Entrypoints } from 'esbuild-plugin-serverless/entrypoint'

const build = async (entrypointConfig: Entrypoints) => {
  process.env.NODE_ENV = 'PRODUCTION'
  const entryPoints = Object.keys(entrypointConfig).map(
    // This should include the path to a folder
    // where your entrypoints reside as individual files or folders
    (entrypoint) => `./src/${entrypoint}`
  )

  // Some packages can break the build process so we can move them outside
  const external = {
    '@yandex-cloud/nodejs-sdk': '*',
    googleapis: '*'
  }
  const context = await createContext({
    entryPoints,
    bundle: true,
    minify: true,
    platform: 'node',
    target: 'node16',
    external: Object.keys(external),
    treeShaking: true,
    outdir: 'build',
    write: false,
    plugins: [esbuildServerlessPlugin(entrypointConfig, external)]
  })
  await context.watch()
}

export default build

Bind build function to dev script by adding it into your package.json

{
  "scripts": {
    "dev": "ts-node chores/index.ts"
  }
}

Add some authorization by providing the following variables from service sccount authorized key. You can use getFromEnv helper.

YC_ACCESS_KEY_ID=
YC_SERVICE_ACCOUNT_ID=
YC_PRIVATE_KEY=

This method is used for security reasons, as using OAuth token is not recommended. If these variables are not provided the library will attempt to authorize from Metadata service. One can also work entirely in the cloud using a VM with service-account attached to it.

Run

npm run dev

and enjoy automatic re-deployment on save