@netlify/vite-plugin 0.3.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/main.d.ts +1 -1
- package/dist/main.js +30 -15
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @netlify/vite-plugin
|
|
2
2
|
|
|
3
|
-
> [!WARNING] This is an experimental Vite plugin for Netlify. It is under active development and does **not** yet
|
|
3
|
+
> [!WARNING] This is an experimental Vite plugin for Netlify. It is under active development and does **not** yet
|
|
4
|
+
> support all Netlify platform features.
|
|
4
5
|
|
|
5
6
|
A Vite plugin that integrates with Netlify's platform features.
|
|
6
7
|
|
|
@@ -14,9 +15,11 @@ npm install @netlify/vite-plugin
|
|
|
14
15
|
|
|
15
16
|
The plugin accepts the following options:
|
|
16
17
|
|
|
17
|
-
- `middleware` (boolean, default: `true`): Attach a Vite middleware that intercepts requests and handles them in the
|
|
18
|
+
- `middleware` (boolean, default: `true`): Attach a Vite middleware that intercepts requests and handles them in the
|
|
19
|
+
same way as the Netlify production environment
|
|
18
20
|
- `blobs`: Configure blob storage functionality
|
|
19
21
|
- `functions`: Configure serverless functions
|
|
22
|
+
- `headers`: Configure response headers
|
|
20
23
|
- `redirects`: Configure URL redirects
|
|
21
24
|
- `staticFiles`: Configure static file serving
|
|
22
25
|
|
|
@@ -29,6 +32,6 @@ import { defineConfig } from 'vite'
|
|
|
29
32
|
import netlify from '@netlify/vite-plugin'
|
|
30
33
|
|
|
31
34
|
export default defineConfig({
|
|
32
|
-
plugins: [netlify()]
|
|
35
|
+
plugins: [netlify()],
|
|
33
36
|
})
|
|
34
37
|
```
|
package/dist/main.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Features } from '@netlify/dev';
|
|
|
3
3
|
interface NetlifyPluginOptions extends Features {
|
|
4
4
|
/**
|
|
5
5
|
* Attach a Vite middleware that intercepts requests and handles them in the
|
|
6
|
-
* same way as the Netlify production environment.
|
|
6
|
+
* same way as the Netlify production environment (default: true).
|
|
7
7
|
*/
|
|
8
8
|
middleware?: boolean;
|
|
9
9
|
}
|
package/dist/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/main.ts
|
|
2
|
-
import process from "
|
|
2
|
+
import process from "process";
|
|
3
3
|
import { NetlifyDev } from "@netlify/dev";
|
|
4
4
|
|
|
5
5
|
// src/lib/logger.ts
|
|
6
6
|
import chalk from "chalk";
|
|
7
7
|
var NETLIFY_CYAN = chalk.rgb(40, 180, 170);
|
|
8
|
-
var banner = NETLIFY_CYAN("\
|
|
8
|
+
var banner = NETLIFY_CYAN("\u2B25 Netlify \u2B25");
|
|
9
9
|
var logger = {
|
|
10
10
|
error: (...data) => data.length === 0 ? console.error(...data) : console.error(banner, ...data),
|
|
11
11
|
log: (...data) => data.length === 0 ? console.log(...data) : console.log(banner, ...data),
|
|
@@ -13,7 +13,7 @@ var logger = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// src/lib/reqres.ts
|
|
16
|
-
import { Readable } from "
|
|
16
|
+
import { Readable } from "stream";
|
|
17
17
|
var normalizeHeaders = (headers) => {
|
|
18
18
|
const result = [];
|
|
19
19
|
for (const [key, value] of Object.entries(headers)) {
|
|
@@ -67,31 +67,46 @@ function netlify(options = {}) {
|
|
|
67
67
|
const plugin = {
|
|
68
68
|
name: "vite-plugin-netlify",
|
|
69
69
|
async configureServer(viteDevServer) {
|
|
70
|
-
const {
|
|
70
|
+
const { port } = viteDevServer.config.server;
|
|
71
|
+
const { blobs, edgeFunctions, functions, middleware = true, redirects, staticFiles } = options;
|
|
71
72
|
const netlifyDev = new NetlifyDev({
|
|
72
73
|
blobs,
|
|
74
|
+
edgeFunctions,
|
|
73
75
|
functions,
|
|
74
76
|
logger,
|
|
75
77
|
redirects,
|
|
76
|
-
|
|
78
|
+
serverAddress: `http://localhost:${port}`,
|
|
79
|
+
staticFiles: {
|
|
80
|
+
...staticFiles,
|
|
81
|
+
directories: [viteDevServer.config.root, viteDevServer.config.publicDir]
|
|
82
|
+
},
|
|
77
83
|
projectRoot: viteDevServer.config.root
|
|
78
84
|
});
|
|
79
85
|
await netlifyDev.start();
|
|
80
86
|
if (!netlifyDev.siteIsLinked) {
|
|
81
|
-
logger.log(
|
|
87
|
+
logger.log(
|
|
88
|
+
"Linking this project to a Netlify site lets you deploy your site, use any environment variables defined on your team and site and much more. Run `npx netlify init` to get started."
|
|
89
|
+
);
|
|
82
90
|
}
|
|
83
91
|
if (middleware) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} else {
|
|
91
|
-
next();
|
|
92
|
+
viteDevServer.middlewares.use(async function netlifyPreMiddleware(nodeReq, nodeRes, next) {
|
|
93
|
+
const req = toWebRequest(nodeReq, nodeReq.originalUrl);
|
|
94
|
+
const headers = {};
|
|
95
|
+
const result = await netlifyDev.handleAndIntrospect(req, {
|
|
96
|
+
headersCollector: (key, value) => {
|
|
97
|
+
headers[key] = value;
|
|
92
98
|
}
|
|
93
99
|
});
|
|
94
|
-
|
|
100
|
+
const isStaticFile = result?.type === "static";
|
|
101
|
+
if (result && !isStaticFile) {
|
|
102
|
+
fromWebResponse(result.response, nodeRes);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const key in headers) {
|
|
106
|
+
nodeRes.setHeader(key, headers[key]);
|
|
107
|
+
}
|
|
108
|
+
next();
|
|
109
|
+
});
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Vite plugin with a local emulation of the Netlify environment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": "
|
|
7
|
+
"node": "^20.6.1 || >=22"
|
|
8
8
|
},
|
|
9
9
|
"main": "./dist/main.js",
|
|
10
10
|
"exports": "./dist/main.js",
|
|
@@ -29,16 +29,17 @@
|
|
|
29
29
|
},
|
|
30
30
|
"author": "Netlify Inc.",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^20.
|
|
32
|
+
"@types/node": "^20.17.57",
|
|
33
|
+
"playwright": "^1.52.0",
|
|
33
34
|
"tsup": "^8.0.0",
|
|
34
35
|
"vite": "^6.3.4",
|
|
35
36
|
"vitest": "^3.0.0"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@netlify/dev": "
|
|
39
|
+
"@netlify/dev": "4.0.0",
|
|
39
40
|
"chalk": "^5.4.1"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"vite": "^6
|
|
43
|
+
"vite": "^6"
|
|
43
44
|
}
|
|
44
45
|
}
|