@brillout/vite-plugin-server-entry
Advanced tools
Comparing version 0.4.13 to 0.5.0
@@ -1,5 +0,5 @@ | ||
export { serverEntryPlugin }; | ||
export { serverProductionEntryPlugin }; | ||
export type { ConfigVitePluginServerEntry }; | ||
type PluginConfigProvidedByLibrary = { | ||
getImporterCode: () => string; | ||
getServerProductionEntry: () => string; | ||
libraryName: string; | ||
@@ -22,7 +22,3 @@ inject?: boolean | string[]; | ||
*/ | ||
declare function serverEntryPlugin(pluginConfigProvidedByLibrary: PluginConfigProvidedByLibrary): Plugin_[]; | ||
declare function serverProductionEntryPlugin(pluginConfigProvidedByLibrary: PluginConfigProvidedByLibrary): Plugin_[]; | ||
type Plugin_ = any; | ||
export { findServerEntry }; | ||
declare function findServerEntry<OutputBundle extends Record<string, { | ||
name: string | undefined; | ||
}>>(bundle: OutputBundle): OutputBundle[string]; |
@@ -6,4 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serverEntryPlugin = serverEntryPlugin; | ||
exports.findServerEntry = findServerEntry; | ||
exports.serverProductionEntryPlugin = serverProductionEntryPlugin; | ||
const utils_1 = require("./utils"); | ||
@@ -28,3 +27,3 @@ const path_1 = __importDefault(require("path")); | ||
*/ | ||
function serverEntryPlugin(pluginConfigProvidedByLibrary) { | ||
function serverProductionEntryPlugin(pluginConfigProvidedByLibrary) { | ||
const pluginName = `@brillout/vite-plugin-server-entry:${pluginConfigProvidedByLibrary.libraryName.toLowerCase()}`; | ||
@@ -74,4 +73,4 @@ let config; | ||
if (id === virtualIdPrefix + serverEntryVirtualId) { | ||
const serverEntryFileContent = getServerEntryFileContent(config); | ||
return serverEntryFileContent; | ||
const serverProductionEntry = getServerProductionEntryAll(config); | ||
return serverProductionEntry; | ||
} | ||
@@ -161,6 +160,4 @@ }, | ||
setInjectConfig(pluginConfigResolved, pluginConfigProvidedByLibrary.inject); | ||
// @ts-expect-error workaround for previously broken api version assertion | ||
pluginConfigResolved.configVersion = 1; | ||
const library = { | ||
getImporterCode: pluginConfigProvidedByLibrary.getImporterCode, | ||
getServerProductionEntry: pluginConfigProvidedByLibrary.getServerProductionEntry, | ||
libraryName: pluginConfigProvidedByLibrary.libraryName, | ||
@@ -214,14 +211,18 @@ pluginVersion: utils_1.projectInfo.projectVersion, | ||
} | ||
function getServerEntryFileContent(config) { | ||
function getServerProductionEntryAll(config) { | ||
(0, utils_1.assert)((0, utils_1.viteIsSSR)(config)); | ||
const serverEntryFileContent = [ | ||
const serverProductionEntry = [ | ||
'// Generated by https://github.com/brillout/vite-plugin-server-entry', | ||
...config._vitePluginServerEntry.libraries.map((library) => { | ||
// Should be true becasue of assertApiVersions() | ||
// Should be true because of assertApiVersions() | ||
(0, utils_1.assert)(getLibraryApiVersion(library) === apiVersion); | ||
const entryCode = library.getImporterCode(); | ||
const entryCode = (library.getServerProductionEntry ?? | ||
// Support old `getServerProductionEntry()` name: it was previously called `getImporterCode()`. | ||
// TODO/api-version-bump: We'll be able to remove this next time we bump `apiVersion`. | ||
// @ts-expect-error | ||
library.getImporterCode)(); | ||
return entryCode; | ||
}) | ||
].join('\n'); | ||
return serverEntryFileContent; | ||
return serverProductionEntry; | ||
} | ||
@@ -228,0 +229,0 @@ function writeAutoImporterFile(config, entryFileName) { |
@@ -1,1 +0,1 @@ | ||
export { importServerEntry } from './importServerEntry'; | ||
export { importServerProductionEntry } from './importServerProductionEntry'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.importServerEntry = void 0; | ||
var importServerEntry_1 = require("./importServerEntry"); | ||
Object.defineProperty(exports, "importServerEntry", { enumerable: true, get: function () { return importServerEntry_1.importServerEntry; } }); | ||
exports.importServerProductionEntry = void 0; | ||
var importServerProductionEntry_1 = require("./importServerProductionEntry"); | ||
Object.defineProperty(exports, "importServerProductionEntry", { enumerable: true, get: function () { return importServerProductionEntry_1.importServerProductionEntry; } }); |
export { assert }; | ||
export { assertUsage }; | ||
export { logLabel }; | ||
declare const logLabel: "[@brillout/vite-plugin-server-entry@0.4.13]"; | ||
declare const logLabel: "[@brillout/vite-plugin-server-entry@0.5.0]"; | ||
declare function assert(condition: unknown, debugInfo?: unknown): asserts condition; | ||
declare function assertUsage(condition: unknown, errorMessage: string): asserts condition; |
@@ -1,1 +0,1 @@ | ||
export declare const PROJECT_VERSION: "0.4.13"; | ||
export declare const PROJECT_VERSION: "0.5.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PROJECT_VERSION = void 0; | ||
exports.PROJECT_VERSION = '0.4.13'; | ||
exports.PROJECT_VERSION = '0.5.0'; |
export declare const projectInfo: { | ||
projectName: "@brillout/vite-plugin-server-entry"; | ||
npmPackageName: "@brillout/vite-plugin-server-entry"; | ||
projectVersion: "0.4.13"; | ||
projectVersion: "0.5.0"; | ||
githubRepository: "https://github.com/brillout/vite-plugin-server-entry"; | ||
}; |
{ | ||
"name": "@brillout/vite-plugin-server-entry", | ||
"version": "0.4.13", | ||
"version": "0.5.0", | ||
"repository": "https://github.com/brillout/vite-plugin-server-entry", | ||
@@ -10,6 +10,3 @@ "dependencies": { | ||
"./plugin": "./dist/plugin/index.js", | ||
"./runtime": "./dist/runtime/index.js", | ||
"./plugin.js": "./dist/plugin/index.js", | ||
"./importServerEntry": "./dist/runtime/index.js", | ||
"./importServerEntry.js": "./dist/runtime/index.js" | ||
"./runtime": "./dist/runtime/index.js" | ||
}, | ||
@@ -48,11 +45,2 @@ "scripts": { | ||
"./dist/runtime/index.d.ts" | ||
], | ||
"plugin.js": [ | ||
"./dist/plugin/index.d.ts" | ||
], | ||
"importServerEntry": [ | ||
"./dist/runtime/index.d.ts" | ||
], | ||
"importServerEntry.js": [ | ||
"./dist/runtime/index.d.ts" | ||
] | ||
@@ -59,0 +47,0 @@ } |
@@ -12,3 +12,3 @@ - [What is this?](#what-is-this) | ||
- Generates the server production entry `dist/server/entry.js`. | ||
- Automatically loads it. | ||
- Automatically imports it. | ||
@@ -22,3 +22,3 @@ [Vike](https://vike.dev) and [Telefunc](https://telefunc.com) automatically use and configure this plugin on your behalf: there is nothing for you to do and you can usually ignore this plugin. | ||
Normally, the `dist/server/entry.js` file is automatically imported. | ||
Normally the file `dist/server/entry.js` is automatically imported. | ||
@@ -28,8 +28,8 @@ But this automatic importing doesn't work with Yarn PnP and certain Docker configurations, and you'll keep getting the following error: | ||
``` | ||
[@brillout/vite-plugin-server-entry][Wrong Usage] The server production entry is missing | ||
or wasn't imported. (Re-)build your app and try again. If you still get this error, | ||
then you need to manually import the server production entry. | ||
[@brillout/vite-plugin-server-entry][Wrong Usage] The server production entry is missing. | ||
(Re-)build your app and try again. If you still get this error, then you need to manually | ||
import the server production entry. | ||
``` | ||
The workaround is to manually import `dist/server/entry.js` in your server code. | ||
The workaround is to manually import `dist/server/entry.js` in your server code: | ||
@@ -42,4 +42,5 @@ ```js | ||
// Your server code (Express.js, Hono, Vercel Serverless/Edge Function, Cloudflare Worker, ...) | ||
// ... | ||
// your server code (Express.js, Hono, Cloudflare Worker, Vercel, ...) | ||
// ... | ||
``` | ||
@@ -50,16 +51,25 @@ | ||
> [!NOTE] | ||
> The file extension may be different than `.js` (e.g. `dist/server/entry.mjs`), and the build directory location is determined by [`vite.config.js` > `build.outDir`](https://vitejs.dev/config/build-options.html#build-outdir) which may be different than `dist/` (e.g. `build/server/entry.js`). Adjust your import accordingly: | ||
> The import path may be different: | ||
> - The file extension may be different than `.js`. (For example `dist/server/entry.mjs`.) | ||
> - The build directory location may be different than `dist/`. (For example `build/server/entry.js` if you set [`vite.config.js` > `build.outDir`](https://vitejs.dev/config/build-options.html#build-outdir) to `build`.) | ||
> | ||
> ```diff | ||
> - import './path/to/dist/server/entry.js | ||
> + import './path/to/build/server/entry.mjs | ||
> - import '../dist/server/entry.js | ||
> + import '../build/server/entry.mjs | ||
> ``` | ||
> [!NOTE] | ||
> If you aren't using Yarn PnP nor Docker and you keep getting this error, then it's most likely a bug and please [file a bug report](https://github.com/brillout/vite-plugin-server-entry/issues/new). | ||
> If you use [Vike](https://vike.dev/) then make sure that you import `dist/server/entry.js` before calling [`renderPage()`](https://vike.dev/renderPage). | ||
> [!NOTE] | ||
> Technically, the automatic importing doesn't work when your `node_modules/` directory is immutable or if you remove/reset `node_modules/` **after** you build your app for production. If you want to know more, see [How it works](#how-it-works). | ||
> If you aren't using Yarn PnP nor Docker and you keep getting the `The server production entry is missing.` error, then [file a bug report](https://github.com/brillout/vite-plugin-server-entry/issues/new). Manually importing should only be needed for Yarn PnP and Docker users. | ||
> [!NOTE] | ||
> Technically, you need to manually import if and only if: | ||
> - your `node_modules/` directory is immutable, or | ||
> - you remove/re-install `node_modules/` *after* building your app for production. | ||
> | ||
> If you want to learn more, see [How it works](#how-it-works). | ||
<p align="center"><sup><a href="#readme"><b>⇧</b> <b>TOP</b> <b>⇧</b></a></sup></p><br/> | ||
@@ -75,7 +85,7 @@ | ||
- Generates a "server production entry" file `dist/server/entry.js`. | ||
- Generates a "auto importer" file `node_modules/@brillout/vite-plugin-server-entry/dist/importServerEntry/autoImporter.js`. | ||
- Generates a "auto importer" file `node_modules/@brillout/vite-plugin-server-entry/dist/runtime/autoImporter.js`. | ||
The *server production entry*, which is located at `dist/server/entry.js`, enables tools such as Vike and Telefunc to consolidate their production entry into a single file. It loads the user files built for production which are located at `dist/**` (e.g. the built `.telefunc.js` user files for Telefunc, and the built `+Page.js` user files for Vike). | ||
The *auto importer* file, which is located at `node_modules/@brillout/vite-plugin-server-entry/dist/importServerEntry/autoImporter.js`, automatically imports `dist/server/entry.js` on your behalf, so that you don't have to manually import `dist/server/entry.js` yourself as shown in the following. That's the only purpose of the auto importer. | ||
The *auto importer* file, which is located at `node_modules/@brillout/vite-plugin-server-entry/dist/runtime/autoImporter.js`, automatically imports `dist/server/entry.js` on your behalf, so that you don't have to manually import `dist/server/entry.js` yourself as shown in the following. That's the only purpose of the auto importer. | ||
@@ -82,0 +92,0 @@ ```js |
54992
1126
99