OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Prevent Next.js from pre compiling certain files

  • Thread starter Thread starter Timsib Adnap
  • Start date Start date
T

Timsib Adnap

Guest
I have next.js project which is used as frontend and a golang project which is used as the backend. To share config between the two, I use a config file, lets say config.toml.

In the next.js project, there is a page, similar to a settings page where I can modify the details of the config file via the golang backend using a REST api.

Now the issue I am facing is how to use the updated config in the next.js website, as it contains some details like SEO metadata. The config file is already pre built into the next.js build output.

So, how do I go about it? I want to prevent next.js from compiling my one file which contains the loading logic.

load-config.ts

Code:
"use server";

import { readFileSync as read } from "fs";
import { parse } from "smol-toml";

import { configSchema } from "./schema";

// This gets pre built and fixed.
const cfg = configSchema.parse(parse(read("/data/config.toml", { encoding: "utf-8" })));

export async function getConfig() {
  return cfg;
}

<p>I have next.js project which is used as frontend and a golang project which is used as the backend.
To share config between the two, I use a config file, lets say <code>config.toml</code>.</p>
<p>In the next.js project, there is a page, similar to a settings page where I can modify the details of the config file via the golang backend using a REST api.</p>
<p>Now the issue I am facing is how to use the updated config in the next.js website, as it contains some details like SEO metadata. The config file is already pre built into the next.js build output.</p>
<p>So, how do I go about it? I want to prevent next.js from compiling my one file which contains the loading logic.</p>
<p><code>load-config.ts</code></p>
<pre><code>"use server";

import { readFileSync as read } from "fs";
import { parse } from "smol-toml";

import { configSchema } from "./schema";

// This gets pre built and fixed.
const cfg = configSchema.parse(parse(read("/data/config.toml", { encoding: "utf-8" })));

export async function getConfig() {
return cfg;
}
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top