@nx/next 18.0.3 → 18.1.0-beta.0
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/migrations.json +9 -0
- package/package.json +9 -9
- package/plugins/with-nx.js +13 -33
- package/src/executors/build/lib/create-next-config-file.js +4 -1
- package/src/generators/custom-server/custom-server.js +29 -8
- package/src/generators/custom-server/files/server/main.ts__tmpl__ +4 -4
- package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +2 -0
- package/src/utils/add-swc-to-custom-server.js +9 -1
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
package/migrations.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "18.0.
|
|
3
|
+
"version": "18.1.0-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Next.js plugin for Nx contains executors and generators for managing Next.js applications and libraries within an Nx workspace. It provides:\n\n\n- Scaffolding for creating, building, serving, linting, and testing Next.js applications.\n\n- Integration with building, serving, and exporting a Next.js application.\n\n- Integration with React libraries within the workspace. \n\nWhen using Next.js in Nx, you get the out-of-the-box support for TypeScript, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"next": ">=14.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nx/devkit": "18.0.
|
|
37
|
+
"@nx/devkit": "18.1.0-beta.0",
|
|
38
38
|
"@babel/plugin-proposal-decorators": "^7.22.7",
|
|
39
39
|
"@svgr/webpack": "^8.0.1",
|
|
40
40
|
"chalk": "^4.1.0",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"url-loader": "^4.1.1",
|
|
46
46
|
"tslib": "^2.3.0",
|
|
47
47
|
"webpack-merge": "^5.8.0",
|
|
48
|
-
"@nx/js": "18.0.
|
|
49
|
-
"@nx/eslint": "18.0.
|
|
50
|
-
"@nx/react": "18.0.
|
|
51
|
-
"@nx/web": "18.0.
|
|
52
|
-
"@nx/webpack": "18.0.
|
|
53
|
-
"@nx/workspace": "18.0.
|
|
54
|
-
"@nrwl/next": "18.0.
|
|
48
|
+
"@nx/js": "18.1.0-beta.0",
|
|
49
|
+
"@nx/eslint": "18.1.0-beta.0",
|
|
50
|
+
"@nx/react": "18.1.0-beta.0",
|
|
51
|
+
"@nx/web": "18.1.0-beta.0",
|
|
52
|
+
"@nx/webpack": "18.1.0-beta.0",
|
|
53
|
+
"@nx/workspace": "18.1.0-beta.0",
|
|
54
|
+
"@nrwl/next": "18.1.0-beta.0"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
package/plugins/with-nx.js
CHANGED
|
@@ -219,39 +219,19 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
|
219
219
|
*/
|
|
220
220
|
// Default SVGR support to be on for projects.
|
|
221
221
|
if (nx?.svgr !== false) {
|
|
222
|
-
config.module.rules.push(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
loader: require.resolve('url-loader'),
|
|
239
|
-
options: {
|
|
240
|
-
limit: 10000, // 10kB
|
|
241
|
-
name: '[name].[hash:7].[ext]',
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
],
|
|
245
|
-
},
|
|
246
|
-
// Fallback to plain URL loader if someone just imports the SVG and references it on the <img src> tag
|
|
247
|
-
{
|
|
248
|
-
loader: require.resolve('url-loader'),
|
|
249
|
-
options: {
|
|
250
|
-
limit: 10000, // 10kB
|
|
251
|
-
name: '[name].[hash:7].[ext]',
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
],
|
|
222
|
+
config.module.rules.push(
|
|
223
|
+
// Apply rule for svg imports ending in ?url
|
|
224
|
+
{
|
|
225
|
+
test: /\.svg$/i,
|
|
226
|
+
type: 'asset',
|
|
227
|
+
resourceQuery: /url/, // apply to *.svg?url
|
|
228
|
+
},
|
|
229
|
+
// Convert all other svg imports to React components
|
|
230
|
+
{
|
|
231
|
+
test: /\.svg$/i,
|
|
232
|
+
issuer: /\.[jt]sx?$/,
|
|
233
|
+
resourceQuery: { not: [/url/] },
|
|
234
|
+
use: ['@svgr/webpack'],
|
|
255
235
|
});
|
|
256
236
|
}
|
|
257
237
|
return userWebpack(config, options);
|
|
@@ -41,7 +41,10 @@ function createNextConfigFile(options, context) {
|
|
|
41
41
|
const moduleFilesToCopy = getRelativeFilesToCopy(configRelativeToProjectRoot, projectRoot);
|
|
42
42
|
for (const moduleFile of moduleFilesToCopy) {
|
|
43
43
|
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)((0, path_1.join)(context.root, options.outputPath, moduleFile)));
|
|
44
|
-
|
|
44
|
+
// We already generate a build version of package.json in the dist folder.
|
|
45
|
+
if (moduleFile !== 'package.json') {
|
|
46
|
+
(0, fs_extra_1.copyFileSync)((0, path_1.join)(context.root, projectRoot, moduleFile), (0, path_1.join)(context.root, options.outputPath, moduleFile));
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
exports.createNextConfigFile = createNextConfigFile;
|
|
@@ -6,17 +6,26 @@ const path_1 = require("path");
|
|
|
6
6
|
const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server");
|
|
7
7
|
async function customServerGenerator(host, options) {
|
|
8
8
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
9
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
10
|
+
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
11
|
+
? p === '@nx/next/plugin'
|
|
12
|
+
: p.plugin === '@nx/next/plugin');
|
|
9
13
|
if (project.targets?.build?.executor !== '@nx/next:build' &&
|
|
10
|
-
project.targets?.build?.executor !== '@nrwl/next:build'
|
|
14
|
+
project.targets?.build?.executor !== '@nrwl/next:build' &&
|
|
15
|
+
!hasPlugin) {
|
|
11
16
|
devkit_1.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
|
|
12
17
|
return;
|
|
13
18
|
}
|
|
14
|
-
|
|
19
|
+
// In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
|
|
20
|
+
const outputPath = hasPlugin
|
|
21
|
+
? `dist/${project.root}`
|
|
22
|
+
: project.targets?.build?.options?.outputPath;
|
|
15
23
|
const root = project.root;
|
|
16
|
-
if (!root ||
|
|
24
|
+
if ((!root ||
|
|
17
25
|
!outputPath ||
|
|
18
26
|
!project.targets?.build?.configurations?.development ||
|
|
19
|
-
!project.targets?.build?.configurations?.production)
|
|
27
|
+
!project.targets?.build?.configurations?.production) &&
|
|
28
|
+
!hasPlugin) {
|
|
20
29
|
devkit_1.logger.error(`Project ${options.project} has invalid config. Did you generate it with "nx g @nx/next:app"?`);
|
|
21
30
|
return;
|
|
22
31
|
}
|
|
@@ -25,16 +34,28 @@ async function customServerGenerator(host, options) {
|
|
|
25
34
|
devkit_1.logger.warn(`Project ${options.project} has custom server targets already: build-custom-server, serve-custom-server. Remove these targets from project and try again.`);
|
|
26
35
|
return;
|
|
27
36
|
}
|
|
37
|
+
// In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
|
|
38
|
+
// So we need ensure the mapping is correct from dist to the project root
|
|
39
|
+
const projectPathFromDist = `../../${(0, devkit_1.offsetFromRoot)(project.root)}${project.root}`;
|
|
28
40
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
|
|
29
41
|
...options,
|
|
42
|
+
hasPlugin,
|
|
43
|
+
projectPathFromDist,
|
|
30
44
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
|
|
31
45
|
projectRoot: project.root,
|
|
32
46
|
tmpl: '',
|
|
33
47
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
if (!hasPlugin) {
|
|
49
|
+
project.targets.build.dependsOn = ['build-custom-server'];
|
|
50
|
+
project.targets.serve.options.customServerTarget = `${options.project}:serve-custom-server`;
|
|
51
|
+
project.targets.serve.configurations.development.customServerTarget = `${options.project}:serve-custom-server:development`;
|
|
52
|
+
project.targets.serve.configurations.production.customServerTarget = `${options.project}:serve-custom-server:production`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
project.targets['build'] = {
|
|
56
|
+
dependsOn: ['^build', 'build-custom-server'],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
38
59
|
project.targets['build-custom-server'] = {
|
|
39
60
|
executor: options.compiler === 'tsc' ? '@nx/js:tsc' : '@nx/js:swc',
|
|
40
61
|
defaultConfiguration: 'production',
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* This is only a minimal custom server to get started.
|
|
3
3
|
* You may want to consider using Express or another server framework, and enable security features such as CORS.
|
|
4
4
|
*
|
|
5
|
-
* For
|
|
6
|
-
* -
|
|
7
|
-
* - Hapi: https://github.com/vercel/next.js/tree/canary/examples/custom-server-hapi
|
|
5
|
+
* For an example, see the Next.js repo:
|
|
6
|
+
* Node - https://github.com/vercel/next.js/blob/canary/examples/custom-server
|
|
8
7
|
*/
|
|
9
8
|
import { createServer } from 'http';
|
|
10
9
|
import { parse } from 'node:url';
|
|
@@ -15,7 +14,8 @@ import next from 'next';
|
|
|
15
14
|
// - The environment variable is set by `@nx/next:server` when running the dev server.
|
|
16
15
|
// - The fallback `__dirname` is for production builds.
|
|
17
16
|
// - Feel free to change this to suit your needs.
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
const dir = process.env.NX_NEXT_DIR || <%- hasPlugin ? `path.join(__dirname, '${projectPathFromDist}')` : `path.join(__dirname, '..')`; %>
|
|
19
19
|
const dev = process.env.NODE_ENV === 'development';
|
|
20
20
|
|
|
21
21
|
// HTTP Server options:
|
|
@@ -12,7 +12,15 @@ function configureForSwc(tree, projectRoot) {
|
|
|
12
12
|
const hasSwcCliDependency = rootPackageJson.dependencies?.['@swc/cli'] ||
|
|
13
13
|
rootPackageJson.devDependencies?.['@swc/cli'];
|
|
14
14
|
if (!tree.exists(swcConfigPath)) {
|
|
15
|
-
(0, add_swc_config_1.addSwcConfig)(tree,
|
|
15
|
+
(0, add_swc_config_1.addSwcConfig)(tree, projectRoot);
|
|
16
|
+
}
|
|
17
|
+
if (tree.exists(swcConfigPath)) {
|
|
18
|
+
(0, devkit_1.updateJson)(tree, swcConfigPath, (json) => {
|
|
19
|
+
return {
|
|
20
|
+
...json,
|
|
21
|
+
exclude: [...json.exclude, '.*.d.ts$'],
|
|
22
|
+
};
|
|
23
|
+
});
|
|
16
24
|
}
|
|
17
25
|
if (!hasSwcDepedency || !hasSwcCliDependency) {
|
|
18
26
|
addSwcDependencies(tree);
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ export declare const tsLibVersion = "^2.3.0";
|
|
|
9
9
|
export declare const swcCliVersion = "~0.1.62";
|
|
10
10
|
export declare const swcCoreVersion = "~1.3.85";
|
|
11
11
|
export declare const swcHelpersVersion = "~0.5.2";
|
|
12
|
-
export declare const swcNodeVersion = "~1.
|
|
12
|
+
export declare const swcNodeVersion = "~1.8.0";
|
package/src/utils/versions.js
CHANGED