@netlify/plugin-nextjs 4.28.5 → 4.28.6
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/lib/helpers/config.js +14 -8
- package/package.json +1 -1
package/lib/helpers/config.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateCustomHeaders = exports.configureHandlerFunctions = exports.updateRequiredServerFiles = exports.getRequiredServerFiles = exports.getNextConfig = void 0;
|
|
6
|
+
exports.generateCustomHeaders = exports.configureHandlerFunctions = exports.hasManuallyAddedModule = exports.updateRequiredServerFiles = exports.getRequiredServerFiles = exports.getNextConfig = void 0;
|
|
7
7
|
const destr_1 = __importDefault(require("destr"));
|
|
8
8
|
const fs_extra_1 = require("fs-extra");
|
|
9
9
|
const pathe_1 = require("pathe");
|
|
@@ -57,7 +57,12 @@ const resolveModuleRoot = (moduleName) => {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
const DEFAULT_EXCLUDED_MODULES = ['sharp', 'electron'];
|
|
60
|
-
const
|
|
60
|
+
const hasManuallyAddedModule = ({ netlifyConfig, moduleName, }) =>
|
|
61
|
+
/* eslint-disable camelcase */
|
|
62
|
+
Object.values(netlifyConfig.functions).some(({ included_files = [] }) => included_files.some((inc) => inc.includes(`node_modules/${moduleName}`)));
|
|
63
|
+
exports.hasManuallyAddedModule = hasManuallyAddedModule;
|
|
64
|
+
/* eslint-enable camelcase */
|
|
65
|
+
const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [], }) => {
|
|
61
66
|
var _a;
|
|
62
67
|
const config = await (0, exports.getRequiredServerFiles)(publish);
|
|
63
68
|
const files = config.files || [];
|
|
@@ -67,19 +72,19 @@ const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [] }
|
|
|
67
72
|
(_a = netlifyConfig.functions)._ipx || (_a._ipx = {});
|
|
68
73
|
netlifyConfig.functions._ipx.node_bundler = 'nft';
|
|
69
74
|
}
|
|
70
|
-
|
|
71
|
-
;
|
|
75
|
+
// If the user has manually added the module to included_files, then don't exclude it
|
|
76
|
+
const excludedModules = DEFAULT_EXCLUDED_MODULES.filter((moduleName) => !(0, exports.hasManuallyAddedModule)({ netlifyConfig, moduleName }));
|
|
72
77
|
[constants_1.HANDLER_FUNCTION_NAME, constants_1.ODB_FUNCTION_NAME, '_api_*'].forEach((functionName) => {
|
|
73
78
|
var _a, _b;
|
|
74
79
|
(_a = netlifyConfig.functions)[functionName] || (_a[functionName] = { included_files: [], external_node_modules: [] });
|
|
75
80
|
netlifyConfig.functions[functionName].node_bundler = 'nft';
|
|
76
81
|
(_b = netlifyConfig.functions[functionName]).included_files || (_b.included_files = []);
|
|
77
|
-
netlifyConfig.functions[functionName].included_files.push('.env', '.env.local', '.env.production', '.env.production.local', './public/locales/**', './next-i18next.config.js', `${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, `${publish}/static/chunks/webpack-middleware*.js`, `!${publish}/server/**/*.js.nft.json`, ...cssFilesToInclude, ...ignore.map((path) => `!${(0, slash_1.default)(path)}`));
|
|
82
|
+
netlifyConfig.functions[functionName].included_files.push('.env', '.env.local', '.env.production', '.env.production.local', './public/locales/**', './next-i18next.config.js', `${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, `${publish}/static/chunks/webpack-middleware*.js`, `!${publish}/server/**/*.js.nft.json`, '!**/node_modules/@next/swc*/**/*', ...cssFilesToInclude, ...ignore.map((path) => `!${(0, slash_1.default)(path)}`));
|
|
78
83
|
const nextRoot = resolveModuleRoot('next');
|
|
79
84
|
if (nextRoot) {
|
|
80
85
|
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`);
|
|
81
86
|
}
|
|
82
|
-
|
|
87
|
+
excludedModules.forEach((moduleName) => {
|
|
83
88
|
const moduleRoot = resolveModuleRoot(moduleName);
|
|
84
89
|
if (moduleRoot) {
|
|
85
90
|
netlifyConfig.functions[functionName].included_files.push(`!${moduleRoot}/**/*`);
|
|
@@ -102,11 +107,11 @@ const buildHeader = (buildHeaderParams) => {
|
|
|
102
107
|
// configuration does not support.
|
|
103
108
|
const sanitizePath = (path) => path.replace(/:[^*/]+\*$/, '*');
|
|
104
109
|
/**
|
|
105
|
-
* Persist
|
|
110
|
+
* Persist Next.js custom headers to the Netlify configuration so the headers work with static files
|
|
106
111
|
* See {@link https://nextjs.org/docs/api-reference/next.config.js/headers} for more information on custom
|
|
107
112
|
* headers in Next.js
|
|
108
113
|
*
|
|
109
|
-
* @param nextConfig - The
|
|
114
|
+
* @param nextConfig - The Next.js configuration
|
|
110
115
|
* @param netlifyHeaders - Existing headers that are already configured in the Netlify configuration
|
|
111
116
|
*/
|
|
112
117
|
const generateCustomHeaders = (nextConfig, netlifyHeaders = []) => {
|
|
@@ -149,3 +154,4 @@ const generateCustomHeaders = (nextConfig, netlifyHeaders = []) => {
|
|
|
149
154
|
}
|
|
150
155
|
};
|
|
151
156
|
exports.generateCustomHeaders = generateCustomHeaders;
|
|
157
|
+
/* eslint-enable max-lines */
|