4.2.2 β€’ Published 6 months ago

@netlify/dev v4.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@netlify/dev

!WARNING This module is under active development and does not yet support all Netlify platform features.

@netlify/dev is a local emulator for the Netlify production environment. While it can be used directly by advanced users, it is primarily designed as a foundational library for higher-level tools like the Netlify CLI and the Netlify Vite Plugin.

It provides a local request pipeline that mimics the Netlify platform’s request handling, including support for Functions, Blobs, Static files, Redirects, and Image CDN.

🚧 Feature Support

FeatureSupported
Functionsβœ… Yes
Edge Functionsβœ… Yes
Blobsβœ… Yes
Cache APIβœ… Yes
Redirects and Rewritesβœ… Yes
Headersβœ… Yes
Environment Variablesβœ… Yes
Image CDNβœ… Yes

Note: Missing features will be added incrementally. This module is not intended to be a full replacement for the Netlify CLI.

πŸ“¦ Installation

npm install @netlify/dev

or

yarn add @netlify/dev

πŸš€ Usage

You can use @netlify/dev to emulate the Netlify runtime in your own development tooling or custom integrations:

import { NetlifyDev } from '@netlify/dev'

const devServer = new NetlifyDev({
  blobs: { enabled: true },
  edgeFunctions: { enabled: true },
  environmentVariables: { enabled: true },
  functions: { enabled: true },
  redirects: { enabled: true },
  staticFiles: {
    enabled: true,
    // OPTIONAL: additional directories containing static files to serve
    // Your `projectRoot` (see below) and your site's `publish` dir are served by default
    directories: ['public'],
  },

  // OPTIONAL: base dir (https://docs.netlify.com/configure-builds/overview/#definitions)
  // Defaults to current working directory
  projectRoot: 'site',
  // OPTIONAL: if your local dev setup has its own HTTP server (e.g. Vite), set its address here
  serverAddress: 'http://localhost:1234',
})

await devServer.start()

const response = await devServer.handle(new Request('http://localhost:8888/path'), {
  // An optional callback that will be called with every header (key and value) coming from header rules.
  // See https://docs.netlify.com/routing/headers/
  headersCollector: (key: string, value: string) => console.log(key, value),
})

console.log(await response.text())

await devServer.stop()

πŸ§ͺ Contributing and feedback

This module is experimental, and we welcome feedback and contributions. Feel free to open issues or pull requests if you encounter bugs or have suggestions.

4.2.2

6 months ago

4.2.1

6 months ago

4.2.0

6 months ago

4.1.4

6 months ago

4.1.3

6 months ago

4.1.2

6 months ago

4.1.1

6 months ago

4.1.0

6 months ago

4.0.2

6 months ago

4.0.1

6 months ago

4.0.0

6 months ago

3.0.0

6 months ago

2.3.1

6 months ago

2.3.0

6 months ago

2.2.2

7 months ago

2.2.1

7 months ago

2.1.2

7 months ago

2.1.1

7 months ago

2.1.0

7 months ago

2.0.0

7 months ago

1.1.2

7 months ago

1.1.0

7 months ago