@netlify/plugin-nextjs 4.0.0-beta.6 → 4.0.0-beta.7
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 +26 -10
- package/lib/.DS_Store +0 -0
- package/lib/helpers/config.js +1 -12
- package/lib/helpers/verification.js +16 -1
- package/lib/index.js +4 -3
- package/lib/templates/getHandler.js +2 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
# Essential Next.js Build Plugin (beta)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
:warning: This is the beta version of the Essential Next.js plugin. For the stable version, refer to
|
|
6
|
+
[Essential Next.js plugin v3](https://github.com/netlify/netlify-plugin-nextjs/tree/v3#readme) :warning:
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<a aria-label="npm version" href="https://www.npmjs.com/package/@netlify/plugin-nextjs">
|
|
@@ -16,16 +16,19 @@
|
|
|
16
16
|
|
|
17
17
|
## What's new in this version
|
|
18
18
|
|
|
19
|
-
Version 4 is a complete rewrite of the Essential Next.js plugin. For full details of everything that's new,
|
|
19
|
+
Version 4 is a complete rewrite of the Essential Next.js plugin. For full details of everything that's new, check out
|
|
20
|
+
[the v4 release notes](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/release-notes/v4.md)
|
|
20
21
|
|
|
21
22
|
## Installing the beta
|
|
22
23
|
|
|
23
|
-
|
|
24
24
|
- Install the module:
|
|
25
|
+
|
|
25
26
|
```shell
|
|
26
27
|
npm install -D @netlify/plugin-nextjs@beta
|
|
27
28
|
```
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
- Change the `publish` directory to `.next` and add the plugin to `netlify.toml` if not already installed:
|
|
31
|
+
|
|
29
32
|
```toml
|
|
30
33
|
[build]
|
|
31
34
|
publish = ".next"
|
|
@@ -34,14 +37,27 @@ publish = ".next"
|
|
|
34
37
|
package = "@netlify/plugin-nextjs"
|
|
35
38
|
```
|
|
36
39
|
|
|
37
|
-
If you previously set
|
|
40
|
+
If you previously set a custom `distDir` in your `next.config.js`, or set `node_bundler` or `external_node_modules` in
|
|
41
|
+
your `netlify.toml` these are no longer needed and can be removed.
|
|
42
|
+
|
|
43
|
+
The `serverless` and `experimental-serverless-trace` targets are deprecated in Next 12, and all builds with this plugin
|
|
44
|
+
will now use the default `server` target. If you previously set the target in your `next.config.js`, you should remove
|
|
45
|
+
it.
|
|
46
|
+
|
|
47
|
+
If you are using a monorepo you will need to change `publish` to point to the full path to the built `.next` directory,
|
|
48
|
+
which may be in a subdirectory. If you have changed your `distDir` then it will need to match that.
|
|
38
49
|
|
|
39
|
-
|
|
50
|
+
If you are using Nx, then you will need to point `publish` to the folder inside `dist`, e.g. `dist/apps/myapp/.next`.
|
|
40
51
|
|
|
41
|
-
If you
|
|
52
|
+
If you currently use redirects or rewrites on your site, see
|
|
53
|
+
[the Rewrites and Redirects guide](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/redirects-rewrites.md)
|
|
54
|
+
for information on changes to how they are handled in this version.
|
|
42
55
|
|
|
43
|
-
If you
|
|
56
|
+
If you want to use Next 12's beta Middleware feature, this will mostly work as expected but please
|
|
57
|
+
[read the docs on some caveats and workarounds](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/middleware.md)
|
|
58
|
+
that are currently needed.
|
|
44
59
|
|
|
45
60
|
## Beta feedback
|
|
46
61
|
|
|
47
|
-
Please share any thoughts, feedback or questions about the beta
|
|
62
|
+
Please share any thoughts, feedback or questions about the beta
|
|
63
|
+
[in our discussion](https://github.com/netlify/netlify-plugin-nextjs/discussions/706).
|
package/lib/.DS_Store
ADDED
|
Binary file
|
package/lib/helpers/config.js
CHANGED
|
@@ -59,24 +59,13 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
|
|
|
59
59
|
if (i18n) {
|
|
60
60
|
netlifyConfig.redirects.push({ from: `${basePath}/:locale/_next/static/*`, to: `/static/:splat`, status: 200 });
|
|
61
61
|
}
|
|
62
|
-
const staticManifest = join(netlifyConfig.build.publish, 'static-manifest.json');
|
|
63
|
-
if (process.env.EXPERIMENTAL_MOVE_STATIC_PAGES && existsSync(staticManifest)) {
|
|
64
|
-
// Static page files need to have a forced redirect for preview mode. Otherwise it's non-forced
|
|
65
|
-
const staticFiles = await readJSON(staticManifest);
|
|
66
|
-
netlifyConfig.redirects.push(...staticFiles.map((file) => ({
|
|
67
|
-
from: `${basePath}/${file}`,
|
|
68
|
-
to: HANDLER_FUNCTION_PATH,
|
|
69
|
-
status: 200,
|
|
70
|
-
force: true,
|
|
71
|
-
conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
|
|
72
|
-
})));
|
|
73
|
-
}
|
|
74
62
|
// This is only used in prod, so dev uses `next dev` directly
|
|
75
63
|
netlifyConfig.redirects.push({ from: `${basePath}/_next/static/*`, to: `/static/:splat`, status: 200 }, {
|
|
76
64
|
from: `${basePath}/*`,
|
|
77
65
|
to: HANDLER_FUNCTION_PATH,
|
|
78
66
|
status: 200,
|
|
79
67
|
conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
|
|
68
|
+
force: true,
|
|
80
69
|
}, ...redirects.map((redirect) => ({
|
|
81
70
|
from: `${basePath}${redirect}`,
|
|
82
71
|
to: ODB_FUNCTION_PATH,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { existsSync, promises } = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { relative } = require('path');
|
|
4
|
-
const { yellowBright, greenBright, blueBright, redBright } = require('chalk');
|
|
4
|
+
const { yellowBright, greenBright, blueBright, redBright, reset } = require('chalk');
|
|
5
5
|
const { async: StreamZip } = require('node-stream-zip');
|
|
6
6
|
const outdent = require('outdent');
|
|
7
7
|
const prettyBytes = require('pretty-bytes');
|
|
@@ -17,6 +17,21 @@ exports.verifyNetlifyBuildVersion = ({ IS_LOCAL, NETLIFY_BUILD_VERSION, failBuil
|
|
|
17
17
|
`);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
+
exports.checkForOldFunctions = async ({ functions }) => {
|
|
21
|
+
const oldFunctions = (await functions.list()).filter(({ name }) => name.startsWith('next_'));
|
|
22
|
+
if (oldFunctions.length !== 0) {
|
|
23
|
+
console.log(yellowBright(outdent `
|
|
24
|
+
We have found the following functions in your site that seem to be left over from the old Next.js plugin (v3). We have guessed this because the name starts with "next_".
|
|
25
|
+
|
|
26
|
+
${reset(oldFunctions.map(({ name }) => `- ${name}`).join('\n'))}
|
|
27
|
+
|
|
28
|
+
If they were created by the old plugin, these functions are likely to cause errors so should be removed. You can do this by deleting the following directories:
|
|
29
|
+
|
|
30
|
+
${reset(oldFunctions.map(({ mainFile }) => `- ${path.relative(process.cwd(), path.dirname(mainFile))}`).join('\n'))}
|
|
31
|
+
|
|
32
|
+
`));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
20
35
|
exports.checkNextSiteHasBuilt = ({ publish, failBuild }) => {
|
|
21
36
|
if (!existsSync(path.join(publish, 'BUILD_ID'))) {
|
|
22
37
|
return failBuild(outdent `
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
const { join, relative } = require('path');
|
|
3
2
|
const { ODB_FUNCTION_NAME } = require('./constants');
|
|
4
3
|
const { restoreCache, saveCache } = require('./helpers/cache');
|
|
5
4
|
const { getNextConfig, configureHandlerFunctions, generateRedirects } = require('./helpers/config');
|
|
6
5
|
const { moveStaticPages, movePublicFiles } = require('./helpers/files');
|
|
7
6
|
const { generateFunctions, setupImageFunction, generatePagesResolver } = require('./helpers/functions');
|
|
8
|
-
const { verifyNetlifyBuildVersion, checkNextSiteHasBuilt, checkForRootPublish, logBetaMessage, checkZipSize, } = require('./helpers/verification');
|
|
7
|
+
const { verifyNetlifyBuildVersion, checkNextSiteHasBuilt, checkForRootPublish, logBetaMessage, checkZipSize, checkForOldFunctions, } = require('./helpers/verification');
|
|
8
|
+
/** @type import("@netlify/build").NetlifyPlugin */
|
|
9
9
|
module.exports = {
|
|
10
10
|
async onPreBuild({ constants, netlifyConfig, utils: { build: { failBuild }, cache, }, }) {
|
|
11
11
|
var _a;
|
|
@@ -36,8 +36,9 @@ module.exports = {
|
|
|
36
36
|
i18n,
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
|
-
async onPostBuild({ netlifyConfig, utils: { cache }, constants: { FUNCTIONS_DIST } }) {
|
|
39
|
+
async onPostBuild({ netlifyConfig, utils: { cache, functions }, constants: { FUNCTIONS_DIST } }) {
|
|
40
40
|
await saveCache({ cache, publish: netlifyConfig.build.publish });
|
|
41
|
+
await checkForOldFunctions({ functions });
|
|
41
42
|
await checkZipSize(join(FUNCTIONS_DIST, `${ODB_FUNCTION_NAME}.zip`));
|
|
42
43
|
},
|
|
43
44
|
onEnd() {
|
|
@@ -103,6 +103,8 @@ const makeHandler = () =>
|
|
|
103
103
|
bridge.listen();
|
|
104
104
|
return async (event, context) => {
|
|
105
105
|
var _a, _b, _c, _d;
|
|
106
|
+
// Ensure that paths are encoded - but don't double-encode them
|
|
107
|
+
event.path = new URL(event.path, event.rawUrl).pathname;
|
|
106
108
|
// Next expects to be able to parse the query from the URL
|
|
107
109
|
const query = new URLSearchParams(event.queryStringParameters).toString();
|
|
108
110
|
event.path = query ? `${event.path}?${query}` : event.path;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.7",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@netlify/functions": "^0.
|
|
55
|
+
"@netlify/functions": "^0.9.0",
|
|
56
56
|
"@netlify/ipx": "^0.0.7",
|
|
57
57
|
"@vercel/node": "^1.11.2-canary.4",
|
|
58
58
|
"chalk": "^4.1.2",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@babel/core": "^7.15.8",
|
|
74
74
|
"@babel/preset-env": "^7.15.8",
|
|
75
|
+
"@netlify/build": "^18.23.0",
|
|
75
76
|
"@netlify/eslint-config-node": "^3.3.0",
|
|
76
77
|
"@testing-library/cypress": "^8.0.1",
|
|
77
78
|
"@types/fs-extra": "^9.0.13",
|