cloudflare-next-intl 0.9.12 → 0.9.13
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 -5
- package/dist/src/vite/auto_dynamic_pages_plugin.d.ts +8 -0
- package/dist/src/vite/auto_dynamic_pages_plugin.js +38 -0
- package/dist/src/vite/index.d.ts +1 -0
- package/dist/src/vite/index.js +1 -0
- package/dist/src/vite/plugin.d.ts +2 -0
- package/dist/src/vite/plugin.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -256,11 +256,12 @@ export default defineConfig({
|
|
|
256
256
|
```
|
|
257
257
|
|
|
258
258
|
##### What `cloudflareNextIntl()` Does
|
|
259
|
-
1. **
|
|
260
|
-
2. **
|
|
261
|
-
3. **
|
|
262
|
-
4. **
|
|
263
|
-
5. **
|
|
259
|
+
1. **Auto Dynamic Pages for SSG (`autoDynamicPages`)**: Automatically scans your Next.js/Vinext App Router pages during Vite configuration (`configResolved`) and inserts `export const dynamic = "force-static"` for all static pages that do not access dynamic APIs. This ensures Vinext builds all public marketing and static pages into SSG HTML automatically without extra build scripts or manually writing `export const dynamic = "force-static"`.
|
|
260
|
+
2. **Build-Time & Dev Image Optimizer (`imageOptimizer`)**: Automatically scans your image directories (`public/images`, `public/icons`), downscales oversized assets, produces sibling formats (`webp` by default; also supports `avif`, `png`, `jpeg`, `gif`, `tiff`, `heif`, `jp2`, `jxl`), generates 8px `.blur.webp` thumbnails with Next.js-matching SVG Gaussian blur placeholders, and provides transparent `<Image placeholder="blur" />` shimming via virtual modules. When more than one format is generated for an image, the shim renders a `<picture>` with one `<source>` per format — ordered exactly as configured — so the browser picks the best format it supports, with the original untouched file as an `onError` fallback if a generated asset fails to load. When the same image is used at different widths across the codebase, each size gets its own generated variant, and each `<Image>` usage automatically resolves to the closest matching size.
|
|
261
|
+
3. **Locale File Bundling & Resolution (`localeFiles`)**: Resolves `@locale-file/*` to your `./messages` directory and transforms dynamic imports into `import.meta.glob('/messages/*.json', { eager: true })` for lightning-fast locale loading on Cloudflare Workers.
|
|
262
|
+
4. **User-Agent Stub (`userAgentStub`)**: Prevents Next.js `user-agent` from importing `node:fs` during workerd runtime execution (which otherwise causes runtime 404 / 500 crashes in Workers proxy/middleware).
|
|
263
|
+
5. **Cloudflare Workers Client Stub (`cfWorkersClientStub`)**: Stubs `cloudflare:workers` in client builds so shared modules can be referenced without client bundling errors.
|
|
264
|
+
6. **Build ID Asset Emission (`buildIdAsset`)**: Emits `BUILD_ID` static asset in the client build directory from `process.env.__VINEXT_SHARED_BUILD_ID` or `process.env.__VINEXT_BUILD_ID`.
|
|
264
265
|
|
|
265
266
|
##### Plugin Options
|
|
266
267
|
All features are enabled by default, and can be individually configured or toggled off:
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { type DynamicPagesCheckMode } from "../dynamic_pages_check/index.js";
|
|
3
|
+
export interface AutoDynamicPagesPluginOptions {
|
|
4
|
+
appDir?: string;
|
|
5
|
+
mode?: DynamicPagesCheckMode;
|
|
6
|
+
target?: 'next' | 'vinext';
|
|
7
|
+
}
|
|
8
|
+
export declare function autoDynamicPagesPlugin(options?: AutoDynamicPagesPluginOptions): Plugin;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { checkDynamicPages } from "../dynamic_pages_check/index.js";
|
|
4
|
+
export function autoDynamicPagesPlugin(options = {}) {
|
|
5
|
+
let ran = false;
|
|
6
|
+
return {
|
|
7
|
+
name: "cloudflare-next-intl-auto-dynamic-pages",
|
|
8
|
+
enforce: "pre",
|
|
9
|
+
async configResolved(config) {
|
|
10
|
+
if (ran)
|
|
11
|
+
return;
|
|
12
|
+
ran = true;
|
|
13
|
+
const root = config.root || process.cwd();
|
|
14
|
+
let appDir = options.appDir;
|
|
15
|
+
if (!appDir) {
|
|
16
|
+
if (existsSync(resolve(root, "src/app"))) {
|
|
17
|
+
appDir = resolve(root, "src/app");
|
|
18
|
+
}
|
|
19
|
+
else if (existsSync(resolve(root, "app"))) {
|
|
20
|
+
appDir = resolve(root, "app");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!appDir || !existsSync(appDir)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
await checkDynamicPages({
|
|
28
|
+
appDir,
|
|
29
|
+
mode: options.mode ?? "fix",
|
|
30
|
+
target: options.target ?? "vinext",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
console.warn("[cloudflare-next-intl] autoDynamicPages check error:", err);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
package/dist/src/vite/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { autoDynamicPagesPlugin, type AutoDynamicPagesPluginOptions } from "./auto_dynamic_pages_plugin.js";
|
|
1
2
|
export { buildIdAsset } from "./build_id_asset.js";
|
|
2
3
|
export { userAgentStubPlugin, USER_AGENT_STUB_ID, USER_AGENT_STUB_CODE } from "./user_agent_stub.js";
|
|
3
4
|
export { cfWorkersClientStubPlugin, CF_WORKERS_CLIENT_STUB_ID, CF_WORKERS_CLIENT_STUB_CODE } from "./cf_workers_client_stub.js";
|
package/dist/src/vite/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { autoDynamicPagesPlugin } from "./auto_dynamic_pages_plugin.js";
|
|
1
2
|
export { buildIdAsset } from "./build_id_asset.js";
|
|
2
3
|
export { userAgentStubPlugin, USER_AGENT_STUB_ID, USER_AGENT_STUB_CODE } from "./user_agent_stub.js";
|
|
3
4
|
export { cfWorkersClientStubPlugin, CF_WORKERS_CLIENT_STUB_ID, CF_WORKERS_CLIENT_STUB_CODE } from "./cf_workers_client_stub.js";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import { type LocaleFilePluginOptions } from "./locale_file_plugin.js";
|
|
3
3
|
import { type ImageOptimizerPluginOptions } from "../image_optimizer/index.js";
|
|
4
|
+
import { type AutoDynamicPagesPluginOptions } from "./auto_dynamic_pages_plugin.js";
|
|
4
5
|
export interface CloudflareNextIntlOptions extends LocaleFilePluginOptions {
|
|
6
|
+
autoDynamicPages?: boolean | AutoDynamicPagesPluginOptions;
|
|
5
7
|
buildIdAsset?: boolean | string;
|
|
6
8
|
localeFiles?: boolean;
|
|
7
9
|
userAgentStub?: boolean;
|
package/dist/src/vite/plugin.js
CHANGED
|
@@ -3,8 +3,14 @@ import { userAgentStubPlugin } from "./user_agent_stub.js";
|
|
|
3
3
|
import { cfWorkersClientStubPlugin } from "./cf_workers_client_stub.js";
|
|
4
4
|
import { localeFilePlugin } from "./locale_file_plugin.js";
|
|
5
5
|
import { imageOptimizerPlugin } from "../image_optimizer/index.js";
|
|
6
|
+
import { autoDynamicPagesPlugin } from "./auto_dynamic_pages_plugin.js";
|
|
6
7
|
export function cloudflareNextIntl(options = {}) {
|
|
7
8
|
const plugins = [];
|
|
9
|
+
if (options.autoDynamicPages !== false) {
|
|
10
|
+
plugins.push(autoDynamicPagesPlugin(typeof options.autoDynamicPages === "object"
|
|
11
|
+
? options.autoDynamicPages
|
|
12
|
+
: undefined));
|
|
13
|
+
}
|
|
8
14
|
if (options.imageOptimizer !== false) {
|
|
9
15
|
plugins.push(imageOptimizerPlugin(typeof options.imageOptimizer === "object"
|
|
10
16
|
? options.imageOptimizer
|