Skip to content

Commit df96dc7

Browse files
authored
Merge branch 'main' into docs/release-notes-4
2 parents 72e9d4e + 68b5662 commit df96dc7

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

docs/large-functions.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ You may see an error about generated functions being too large. This is because
44
There are two possible causes for this, each with its own solution. The list of largest files shown in the build logs will help you see what the cause is.
55

66
- **Large dependencies**
7-
This is the most common cause of the problem. Some node modules are very large, mostly those that include native modules. Examples include `electron` and `chromium`. The function bundler is usually able to find out which modules are actually used by your code, but sometimes it will incorrectly include unneeded modules. If this is the case, you can either remove the module from your dependencies if you installed it yourself, or exclude it manually by adding something like this to your `netlify.toml`, changing the value according to the problematic module:
7+
This is the most common cause of the problem. Some node modules are very large, mostly those that include native modules. Examples include `electron` and `chromium`. The function bundler is usually able to find out which modules are actually used by your code, but sometimes it will incorrectly include unneeded modules. If this is the case, you can either remove the module from your dependencies if you installed it yourself, or exclude it manually by adding something like this to your `netlify.toml`, changing the value according to the problematic module. The `!` at the beginning of the module path indicates that it should be excluded:
88

99
```toml
1010
[functions]
11-
excluded_files = "node_modules/electron/**/*"
11+
included_files = ["!node_modules/a-large-module/**/*"]
1212
```
13-
If you do need large modules (e.g. if you are running Puppeteer in a Next API route), consider changing to a Netlify function which will have less overhead than the equivalent Next.js function.
13+
14+
If you do need large modules at runtime (e.g. if you are running Puppeteer in a Next API route), consider changing to a Netlify function which will have less overhead than the equivalent Next.js function.
1415

1516
- **Large numbers of pre-rendered pages**
1617
If you have a very large number of pre-rendered pages, these can take up a lot of space in the function. There are two approaches to fixing this. One is to consider deferring the building of the pages. If you return `fallback: "blocking"` from `getStaticPaths` the rendering will be deferred until the first user requests the page. This is a good choice for low-traffic pages. It reduces build and deploy time, and can make your bundle a lot smaller.

package-lock.json

+28-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
},
5353
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
5454
"dependencies": {
55-
"@netlify/functions": "^0.7.2",
55+
"@netlify/functions": "^0.8.0",
5656
"@netlify/ipx": "^0.0.7",
5757
"@vercel/node": "^1.11.2-canary.4",
5858
"chalk": "^4.1.2",

src/helpers/config.js

+5
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,10 @@ exports.configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) =>
150150
if (sharpRoot) {
151151
netlifyConfig.functions[functionName].included_files.push(`!${sharpRoot}/**/*`)
152152
}
153+
154+
const electronRoot = resolveModuleRoot('electron')
155+
if (electronRoot) {
156+
netlifyConfig.functions[functionName].included_files.push(`!${electronRoot}/**/*`)
157+
}
153158
})
154159
}

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ module.exports = {
7171
})
7272
},
7373

74-
async onPostBuild({ netlifyConfig, utils: { cache }, constants }) {
74+
async onPostBuild({ netlifyConfig, utils: { cache }, constants: { FUNCTIONS_DIST } }) {
7575
await saveCache({ cache, publish: netlifyConfig.build.publish })
76-
await checkZipSize(join(process.cwd(), constants.FUNCTIONS_DIST, `${ODB_FUNCTION_NAME}.zip`))
76+
await checkZipSize(join(FUNCTIONS_DIST, `${ODB_FUNCTION_NAME}.zip`))
7777
},
7878
onEnd() {
7979
logBetaMessage()

0 commit comments

Comments
 (0)