@netlify/plugin-nextjs 4.0.0-beta.4 → 4.0.0-beta.5

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.
@@ -1,5 +1,5 @@
1
1
  // @ts-check
2
- const { readJSON } = require('fs-extra');
2
+ const { readJSON, existsSync } = require('fs-extra');
3
3
  const { join, dirname, relative } = require('pathe');
4
4
  const slash = require('slash');
5
5
  const defaultFailBuild = (message, { error }) => {
@@ -59,12 +59,23 @@ 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
+ }
62
74
  // This is only used in prod, so dev uses `next dev` directly
63
75
  netlifyConfig.redirects.push({ from: `${basePath}/_next/static/*`, to: `/static/:splat`, status: 200 }, {
64
76
  from: `${basePath}/*`,
65
77
  to: HANDLER_FUNCTION_PATH,
66
78
  status: 200,
67
- force: true,
68
79
  conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
69
80
  }, ...redirects.map((redirect) => ({
70
81
  from: `${basePath}${redirect}`,
@@ -92,6 +103,7 @@ const resolveModuleRoot = (moduleName) => {
92
103
  return null;
93
104
  }
94
105
  };
106
+ const DEFAULT_EXCLUDED_MODULES = ['sharp', 'electron'];
95
107
  exports.configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) => {
96
108
  var _a;
97
109
  /* eslint-disable no-underscore-dangle */
@@ -102,18 +114,16 @@ exports.configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) =>
102
114
  (_a = netlifyConfig.functions)[functionName] || (_a[functionName] = { included_files: [], external_node_modules: [] });
103
115
  netlifyConfig.functions[functionName].node_bundler = 'nft';
104
116
  (_b = netlifyConfig.functions[functionName]).included_files || (_b.included_files = []);
105
- netlifyConfig.functions[functionName].included_files.push(`${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, ...ignore.map((path) => `!${slash(path)}`));
117
+ netlifyConfig.functions[functionName].included_files.push(`${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, `${publish}/static/chunks/webpack-middleware*.js`, ...ignore.map((path) => `!${slash(path)}`));
106
118
  const nextRoot = resolveModuleRoot('next');
107
119
  if (nextRoot) {
108
120
  netlifyConfig.functions[functionName].included_files.push(`!${nextRoot}/dist/server/lib/squoosh/**/*.wasm`, `!${nextRoot}/dist/next-server/server/lib/squoosh/**/*.wasm`, `!${nextRoot}/dist/compiled/webpack/bundle4.js`, `!${nextRoot}/dist/compiled/webpack/bundle5.js`, `!${nextRoot}/dist/compiled/terser/bundle.min.js`);
109
121
  }
110
- const sharpRoot = resolveModuleRoot('sharp');
111
- if (sharpRoot) {
112
- netlifyConfig.functions[functionName].included_files.push(`!${sharpRoot}/**/*`);
113
- }
114
- const electronRoot = resolveModuleRoot('electron');
115
- if (electronRoot) {
116
- netlifyConfig.functions[functionName].included_files.push(`!${electronRoot}/**/*`);
117
- }
122
+ DEFAULT_EXCLUDED_MODULES.forEach((moduleName) => {
123
+ const moduleRoot = resolveModuleRoot(moduleName);
124
+ if (moduleRoot) {
125
+ netlifyConfig.functions[functionName].included_files.push(`!${moduleRoot}/**/*`);
126
+ }
127
+ });
118
128
  });
119
129
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -58,7 +58,7 @@
58
58
  "chalk": "^4.1.2",
59
59
  "fs-extra": "^10.0.0",
60
60
  "moize": "^6.1.0",
61
- "node-fetch": "^2.6.5",
61
+ "node-fetch": "^2.6.6",
62
62
  "node-stream-zip": "^1.15.0",
63
63
  "outdent": "^0.8.0",
64
64
  "p-limit": "^3.1.0",
@@ -83,7 +83,7 @@
83
83
  "husky": "^4.3.0",
84
84
  "jest": "^27.0.0",
85
85
  "netlify-plugin-cypress": "^2.2.0",
86
- "next": "^11.1.2",
86
+ "next": "^12.0.2",
87
87
  "npm-run-all": "^4.1.5",
88
88
  "prettier": "^2.1.2",
89
89
  "react": "^17.0.1",