@netlify/vite-plugin 2.5.9 → 2.6.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/dist/main.d.ts +22 -0
- package/dist/main.js +96 -3
- package/package.json +6 -5
package/dist/main.d.ts
CHANGED
|
@@ -6,6 +6,28 @@ interface NetlifyPluginOptions extends Features {
|
|
|
6
6
|
* same way as the Netlify production environment (default: true).
|
|
7
7
|
*/
|
|
8
8
|
middleware?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* DO NOT USE - build options, not meant for public use at this time.
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
build?: {
|
|
14
|
+
/**
|
|
15
|
+
* Prepare the server build for deployment to Netlify - no additional configuration,
|
|
16
|
+
* plugins, or adapters necessary (default: false).
|
|
17
|
+
*
|
|
18
|
+
* This is currently only supported for TanStack Start projects.
|
|
19
|
+
*/
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Deploy SSR handler to Netlify Edge Functions instead of Netlify Functions (default: false).
|
|
23
|
+
*/
|
|
24
|
+
edgeSSR?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A display name for the serverless function or edge function deployed to Netlify
|
|
27
|
+
* (default: `@netlify/vite-plugin server handler`).
|
|
28
|
+
*/
|
|
29
|
+
displayName?: string;
|
|
30
|
+
};
|
|
9
31
|
}
|
|
10
32
|
declare function netlify(options?: NetlifyPluginOptions): any;
|
|
11
33
|
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/main.ts
|
|
2
2
|
import process from "process";
|
|
3
3
|
import { NetlifyDev } from "@netlify/dev";
|
|
4
|
-
import { fromWebResponse, netlifyCommand } from "@netlify/dev-utils";
|
|
4
|
+
import { fromWebResponse, netlifyCommand, warning } from "@netlify/dev-utils";
|
|
5
|
+
import dedent from "dedent";
|
|
5
6
|
|
|
6
7
|
// src/lib/logger.ts
|
|
7
8
|
import { netlifyBanner } from "@netlify/dev-utils";
|
|
@@ -11,18 +12,96 @@ var createLoggerFromViteLogger = (viteLogger) => ({
|
|
|
11
12
|
warn: (msg) => viteLogger.warn(msg ?? "", { timestamp: true, environment: netlifyBanner })
|
|
12
13
|
});
|
|
13
14
|
|
|
15
|
+
// src/lib/build.ts
|
|
16
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
17
|
+
import { join, relative, sep } from "path";
|
|
18
|
+
import { sep as posixSep } from "path/posix";
|
|
19
|
+
import js from "dedent";
|
|
20
|
+
|
|
21
|
+
// package.json
|
|
22
|
+
var name = "@netlify/vite-plugin";
|
|
23
|
+
var version = "2.6.0";
|
|
24
|
+
|
|
25
|
+
// src/lib/build.ts
|
|
26
|
+
var NETLIFY_FUNCTIONS_DIR = ".netlify/v1/functions";
|
|
27
|
+
var NETLIFY_FUNCTION_FILENAME = "server.mjs";
|
|
28
|
+
var NETLIFY_FUNCTION_DEFAULT_NAME = "@netlify/vite-plugin server handler";
|
|
29
|
+
var toPosixPath = (path) => path.split(sep).join(posixSep);
|
|
30
|
+
var createNetlifyFunctionHandler = (serverEntrypointPath, displayName) => js`
|
|
31
|
+
import serverEntrypoint from "${serverEntrypointPath}";
|
|
32
|
+
|
|
33
|
+
if (typeof serverEntrypoint?.fetch !== "function") {
|
|
34
|
+
console.error("The server entry point must have a default export with a property \`fetch: (req: Request) => Promise<Response>\`");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default serverEntrypoint.fetch;
|
|
38
|
+
|
|
39
|
+
export const config = {
|
|
40
|
+
name: "${displayName}",
|
|
41
|
+
generator: "${name}@${version}",
|
|
42
|
+
path: "/*",
|
|
43
|
+
preferStatic: true,
|
|
44
|
+
};
|
|
45
|
+
`;
|
|
46
|
+
var getServerEntrypoint = (bundle, outDir) => {
|
|
47
|
+
const entryChunks = Object.values(bundle).filter(
|
|
48
|
+
(chunk) => chunk.type === "chunk" && chunk.isEntry
|
|
49
|
+
);
|
|
50
|
+
if (entryChunks.length === 0) {
|
|
51
|
+
throw new Error("Could not find entry chunk in bundle - aborting!");
|
|
52
|
+
}
|
|
53
|
+
if (entryChunks.length > 1) {
|
|
54
|
+
throw new Error("Found multiple entry chunks, unable to resolve server entry point - aborting!");
|
|
55
|
+
}
|
|
56
|
+
return join(outDir, entryChunks[0].fileName);
|
|
57
|
+
};
|
|
58
|
+
function createBuildPlugin(options) {
|
|
59
|
+
let resolvedConfig;
|
|
60
|
+
return {
|
|
61
|
+
name: "vite-plugin-netlify:build",
|
|
62
|
+
apply: "build",
|
|
63
|
+
/** @see {@link https://vite.dev/guide/api-environment-plugins.html#per-environment-plugins} */
|
|
64
|
+
applyToEnvironment({ name: name2 }) {
|
|
65
|
+
return name2 === "ssr";
|
|
66
|
+
},
|
|
67
|
+
/** @see {@link https://vite.dev/guide/api-plugin.html#configresolved} */
|
|
68
|
+
configResolved(config) {
|
|
69
|
+
resolvedConfig = config;
|
|
70
|
+
},
|
|
71
|
+
/** @see {@link https://rollupjs.org/plugin-development/#writebundle} */
|
|
72
|
+
async writeBundle(_, bundle) {
|
|
73
|
+
const functionsDirectory = join(resolvedConfig.root, NETLIFY_FUNCTIONS_DIR);
|
|
74
|
+
await mkdir(functionsDirectory, { recursive: true });
|
|
75
|
+
const serverEntrypoint = getServerEntrypoint(bundle, resolvedConfig.build.outDir);
|
|
76
|
+
const serverEntrypointRelativePath = toPosixPath(relative(functionsDirectory, serverEntrypoint));
|
|
77
|
+
await writeFile(
|
|
78
|
+
join(functionsDirectory, NETLIFY_FUNCTION_FILENAME),
|
|
79
|
+
createNetlifyFunctionHandler(
|
|
80
|
+
serverEntrypointRelativePath,
|
|
81
|
+
options?.displayName ?? NETLIFY_FUNCTION_DEFAULT_NAME
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
createLoggerFromViteLogger(resolvedConfig.logger).log(
|
|
85
|
+
`\u2713 Wrote SSR entry point to ${join(NETLIFY_FUNCTIONS_DIR, NETLIFY_FUNCTION_FILENAME)}
|
|
86
|
+
`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
14
92
|
// src/main.ts
|
|
15
93
|
function netlify(options = {}) {
|
|
16
94
|
if (process.env.NETLIFY_DEV) {
|
|
17
95
|
return [];
|
|
18
96
|
}
|
|
19
|
-
const
|
|
97
|
+
const devPlugin = {
|
|
20
98
|
name: "vite-plugin-netlify",
|
|
21
99
|
async configureServer(viteDevServer) {
|
|
22
100
|
if (!viteDevServer.httpServer) {
|
|
23
101
|
return;
|
|
24
102
|
}
|
|
25
103
|
const logger = createLoggerFromViteLogger(viteDevServer.config.logger);
|
|
104
|
+
warnOnDuplicatePlugin(logger);
|
|
26
105
|
const {
|
|
27
106
|
blobs,
|
|
28
107
|
edgeFunctions,
|
|
@@ -81,8 +160,22 @@ function netlify(options = {}) {
|
|
|
81
160
|
}
|
|
82
161
|
}
|
|
83
162
|
};
|
|
84
|
-
|
|
163
|
+
const { enabled, ...buildOptions } = options.build ?? {};
|
|
164
|
+
return [devPlugin, ...enabled === true ? [createBuildPlugin(buildOptions)] : []];
|
|
85
165
|
}
|
|
166
|
+
var warnOnDuplicatePlugin = (logger) => {
|
|
167
|
+
if (process.env.__VITE_PLUGIN_NETLIFY_LOADED__) {
|
|
168
|
+
logger.warn(
|
|
169
|
+
warning(dedent`
|
|
170
|
+
Multiple instances of @netlify/vite-plugin have been loaded. This may cause unexpected \
|
|
171
|
+
behavior if the plugin is configured differently in each instance. If you have one \
|
|
172
|
+
instance of this plugin in your Vite config, you may safely remove it.
|
|
173
|
+
`)
|
|
174
|
+
);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
process.env.__VITE_PLUGIN_NETLIFY_LOADED__ = "true";
|
|
178
|
+
};
|
|
86
179
|
export {
|
|
87
180
|
netlify as default
|
|
88
181
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/vite-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Vite plugin with a local emulation of the Netlify environment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepack": "npm run build",
|
|
18
18
|
"test": "vitest run",
|
|
19
19
|
"test:dev": "vitest",
|
|
20
|
-
"test:ci": "
|
|
20
|
+
"test:ci": "vitest run",
|
|
21
21
|
"dev": "tsup-node --watch",
|
|
22
22
|
"publint": "npx -y publint --strict"
|
|
23
23
|
},
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
"@types/node": "^20.17.57",
|
|
37
37
|
"playwright": "^1.52.0",
|
|
38
38
|
"tsup": "^8.0.0",
|
|
39
|
-
"vite": "^6.3.
|
|
39
|
+
"vite": "^6.3.6",
|
|
40
40
|
"vitest": "^3.0.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@netlify/dev": "4.5.
|
|
44
|
-
"@netlify/dev-utils": "^4.
|
|
43
|
+
"@netlify/dev": "4.5.11",
|
|
44
|
+
"@netlify/dev-utils": "^4.2.0",
|
|
45
|
+
"dedent": "^1.7.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"vite": "^5 || ^6 || ^7"
|