How to ignore a folder when running "next build" #11113
-
When we run "next build" in our production server, it takes +20mins for the process to finish.
is there a way to prevent the build command from going through each folder and file inside the uploads folder because they are only used for serving static pictures and assets. maybe adding an argument inside "next.config.js" to exclude specific folders? thank you for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments 28 replies
-
does anyone have a solution for this? |
Beta Was this translation helpful? Give feedback.
-
still waiting for a solution |
Beta Was this translation helpful? Give feedback.
-
While I aggree such a feature could help migitating this, I guess it would be better to solve the underlying issues for now. One thing you could do is switch to docker, and preferabbly, build the image which already contains the output of |
Beta Was this translation helpful? Give feedback.
-
facing same issue |
Beta Was this translation helpful? Give feedback.
-
In the past I've done something like host user uploads in a AWS S3 bucket, instead of allowing users to upload assets to my source code. I think this is a safer approach and decouples user-uploaded files from the production server. I've only done this in Python, (Using this module) but I'm sure there's a parallel module in Node. Good luck! |
Beta Was this translation helpful? Give feedback.
-
I also need to be able to tell Next to ignore certain files in the build process. |
Beta Was this translation helpful? Give feedback.
-
This issue was fixed on next@canary, please try it out. |
Beta Was this translation helpful? Give feedback.
-
We still have a similar issue with any code colocated with sources, eg For reference I need that to be able to remove test dependencies from my build and have slimmer docker images. |
Beta Was this translation helpful? Give feedback.
-
My workaround for this was adding the redundant folder to You can still have your IDE type-check the directories you don't want Next to check by adding a local tsconfig: . ├── nextDontCompile │ ├── index.tsx │ └── tsconfig.json (local) ├── src │ ├── index.tsx │ └── utils.ts └── tsconfig.json (Next) This seems messy, but it is ultimately what you want here: Your Firebase functions or whatever are really a separate project that are not part of the root-level Next project, and so it makes sense to ignore them. You can also extend the root-level config to prevent having to duplicate your settings:
|
Beta Was this translation helpful? Give feedback.
-
I would like to second a need for an option to ignore a directory when running |
Beta Was this translation helpful? Give feedback.
-
How can I ignore a folder when running |
Beta Was this translation helpful? Give feedback.
-
Made a poor man's patch to implement the feature of ignoring pages on build: diff --git a/dist/build/entries.js b/dist/build/entries.js
index a455fef61988ef553069946b1138ca8dec7e9918..12d4682124c8a089d7b98cfbe77b39a2e4a53c92 100644
--- a/dist/build/entries.js
+++ b/dist/build/entries.js
@@ -153,7 +153,7 @@ function getPageFilePath({ absolutePagePath , pagesDir , appDir , rootDir }) {
}
return require.resolve(absolutePagePath);
}
-function createPagesMapping({ isDev , pageExtensions , pagePaths , pagesType , pagesDir }) {
+function createPagesMapping({ isDev , pageExtensions , ignorePages , pagePaths , pagesType , pagesDir }) {
const isAppRoute = pagesType === "app";
const previousPages = {};
const pages = pagePaths.reduce((result, pagePath)=>{
@@ -161,6 +161,10 @@ function createPagesMapping({ isDev , pageExtensions , pagePaths , pagesType , p
if (pagePath.endsWith(".d.ts") && pageExtensions.includes("ts")) {
return result;
}
+ const ignorePagesArray = Array.isArray(ignorePages) ? ignorePages : ignorePages ? [ignorePages] : [];
+ if (ignorePagesArray.some((regex) => regex.test(pagePath))) {
+ return result;
+ }
let pageKey = getPageFromPath(pagePath, pageExtensions);
if (isAppRoute) {
pageKey = pageKey.replace(/%5F/g, "_");
diff --git a/dist/build/index.js b/dist/build/index.js
index 667a9efe1a4c24ba087a5d7a5ac8e8e6fb15ca10..ad1d5fd36d7732b229a8fa67110ea936870736dd 100644
--- a/dist/build/index.js
+++ b/dist/build/index.js
@@ -275,6 +275,7 @@ async function build(dir, reactProductionProfiling = false, debugOutput = false,
const mappedPages = nextBuildSpan.traceChild("create-pages-mapping").traceFn(()=>(0, _entries.createPagesMapping)({
isDev: false,
pageExtensions: config.pageExtensions,
+ ignorePages: config.ignorePages,
pagesType: "pages",
pagePaths: pagesPaths,
pagesDir
diff --git a/dist/server/config.js b/dist/server/config.js
index e9232bcb5dc81256f80ca82076384e68d009301a..2aa9c55635fe0f424cd195b64c99615658a55ddd 100644
--- a/dist/server/config.js
+++ b/dist/server/config.js
@@ -172,6 +172,21 @@ function assignDefaults(dir, userConfig, silent = false) {
}
});
}
+ if (key === "ignorePages") {
+ if (Array.isArray(value)) {
+ if (!value.length) {
+ throw new Error(`Specified ignorePages is an empty array. Please update it with the relevant RegExps or remove it.`);
+ }
+ value.forEach((regex)=>{
+ if (!(regex instanceof RegExp)) {
+ throw new Error(`Specified ignorePages is not an array of RegExps, found "${regex}" of type "${typeof regex}". Please update this config or remove it.`);
+ }
+ });
+ } else if (!(value instanceof RegExp)) {
+ throw new Error(`Specified ignorePages is neither an array nor a RegExp, found "${value}". Please update this config or remove it.`);
+ }
+
+ }
if (!!value && value.constructor === Object) {
currentConfig[key] = {
..._configshared.defaultConfig[key], Also, you'll have to dig into This patch doesn't work in dev environment, you will still be able to open an ignored page while developing. The |
Beta Was this translation helpful? Give feedback.
-
Bump for visibility i still dont see this working with next.config.js exclude. ( "next": "14.2.5" ) |
Beta Was this translation helpful? Give feedback.
-
@JasonSimms if you are using typescript just add folder name in |
Beta Was this translation helpful? Give feedback.
This issue was fixed on next@canary, please try it out.