@nx/next 18.2.2 → 18.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "18.2.2",
3
+ "version": "18.2.4",
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,24 +34,24 @@
34
34
  "next": ">=14.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "18.2.2",
37
+ "@nx/devkit": "18.2.4",
38
38
  "@babel/plugin-proposal-decorators": "^7.22.7",
39
39
  "@svgr/webpack": "^8.0.1",
40
40
  "chalk": "^4.1.0",
41
41
  "copy-webpack-plugin": "^10.2.4",
42
+ "file-loader": "^6.2.0",
42
43
  "fs-extra": "^11.1.0",
43
44
  "ignore": "^5.0.4",
44
45
  "semver": "^7.5.3",
45
- "url-loader": "^4.1.1",
46
46
  "tslib": "^2.3.0",
47
47
  "webpack-merge": "^5.8.0",
48
- "@nx/js": "18.2.2",
49
- "@nx/eslint": "18.2.2",
50
- "@nx/react": "18.2.2",
51
- "@nx/web": "18.2.2",
52
- "@nx/webpack": "18.2.2",
53
- "@nx/workspace": "18.2.2",
54
- "@nrwl/next": "18.2.2"
48
+ "@nx/js": "18.2.4",
49
+ "@nx/eslint": "18.2.4",
50
+ "@nx/react": "18.2.4",
51
+ "@nx/web": "18.2.4",
52
+ "@nx/webpack": "18.2.4",
53
+ "@nx/workspace": "18.2.4",
54
+ "@nrwl/next": "18.2.4"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"
@@ -224,19 +224,54 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
224
224
  */
225
225
  // Default SVGR support to be on for projects.
226
226
  if (nx?.svgr !== false) {
227
- config.module.rules.push(
228
- // Apply rule for svg imports ending in ?url
229
- {
230
- test: /\.svg$/i,
231
- type: 'asset',
232
- resourceQuery: /url/, // apply to *.svg?url
233
- },
234
- // Convert all other svg imports to React components
235
- {
236
- test: /\.svg$/i,
237
- issuer: /\.[jt]sx?$/,
238
- resourceQuery: { not: [/url/] },
239
- use: ['@svgr/webpack'],
227
+ // TODO(v20): Remove file-loader and use `?react` querystring to differentiate between asset and SVGR.
228
+ // It should be:
229
+ // use: [{
230
+ // test: /\.svg$/i,
231
+ // type: 'asset',
232
+ // resourceQuery: /react/, // *.svg?react
233
+ // },
234
+ // {
235
+ // test: /\.svg$/i,
236
+ // issuer: /\.[jt]sx?$/,
237
+ // resourceQuery: { not: [/react/] }, // exclude react component if *.svg?react
238
+ // use: ['@svgr/webpack'],
239
+ // }],
240
+ // See:
241
+ // - SVGR: https://react-svgr.com/docs/webpack/#use-svgr-and-asset-svg-in-the-same-project
242
+ // - Vite: https://www.npmjs.com/package/vite-plugin-svgr
243
+ // - Rsbuild: https://github.com/web-infra-dev/rsbuild/pull/1783
244
+ // Note: We also need a migration for any projects that are using SVGR to convert
245
+ // `import { ReactComponent as X } from './x.svg` to
246
+ // `import X from './x.svg?react';
247
+ config.module.rules.push({
248
+ test: /\.svg$/,
249
+ issuer: { not: /\.(css|scss|sass)$/ },
250
+ resourceQuery: {
251
+ not: [
252
+ /__next_metadata__/,
253
+ /__next_metadata_route__/,
254
+ /__next_metadata_image_meta__/,
255
+ ],
256
+ },
257
+ use: [
258
+ {
259
+ loader: require.resolve('@svgr/webpack'),
260
+ options: {
261
+ svgo: false,
262
+ titleProp: true,
263
+ ref: true,
264
+ },
265
+ },
266
+ {
267
+ loader: require.resolve('file-loader'),
268
+ options: {
269
+ // Next.js hard-codes assets to load from "static/media".
270
+ // See: https://github.com/vercel/next.js/blob/53d017d/packages/next/src/build/webpack-config.ts#L1993
271
+ name: 'static/media/[name].[hash].[ext]',
272
+ },
273
+ },
274
+ ],
240
275
  });
241
276
  }
242
277
  return userWebpack(config, options);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applicationGeneratorInternal = exports.applicationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
+ const react_1 = require("@nx/react");
6
7
  const versions_1 = require("@nx/react/src/utils/versions");
7
8
  const normalize_options_1 = require("./lib/normalize-options");
8
9
  const add_e2e_1 = require("./lib/add-e2e");
@@ -50,6 +51,12 @@ async function applicationGeneratorInternal(host, schema) {
50
51
  tasks.push(jestTask);
51
52
  const lintTask = await (0, add_linting_1.addLinting)(host, options);
52
53
  tasks.push(lintTask);
54
+ if (options.style === 'tailwind') {
55
+ const tailwindTask = await (0, react_1.setupTailwindGenerator)(host, {
56
+ project: options.projectName,
57
+ });
58
+ tasks.push(tailwindTask);
59
+ }
53
60
  const styledTask = (0, styles_1.addStyleDependencies)(host, {
54
61
  style: options.style,
55
62
  swc: !host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, '.babelrc')),
@@ -33,12 +33,12 @@ async function addE2e(host, options) {
33
33
  project: options.e2eProjectName,
34
34
  directory: 'src',
35
35
  skipFormat: true,
36
- devServerTarget: `${options.projectName}:${hasPlugin ? 'start' : 'serve'}`,
37
- baseUrl: `http://localhost:${hasPlugin ? '3000' : '4200'}`,
36
+ devServerTarget: `${options.projectName}:${options.e2eWebServerTarget}`,
37
+ baseUrl: options.e2eWebServerAddress,
38
38
  jsx: true,
39
39
  webServerCommands: hasPlugin
40
40
  ? {
41
- default: `nx run ${options.projectName}:start`,
41
+ default: `nx run ${options.projectName}:${options.e2eWebServerTarget}`,
42
42
  }
43
43
  : undefined,
44
44
  ciWebServerCommand: hasPlugin
@@ -63,8 +63,8 @@ async function addE2e(host, options) {
63
63
  js: false,
64
64
  linter: options.linter,
65
65
  setParserOptionsProject: options.setParserOptionsProject,
66
- webServerAddress: `http://127.0.0.1:${hasPlugin ? '3000' : '4200'}`,
67
- webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${hasPlugin ? 'start' : 'serve'} ${options.projectName}`,
66
+ webServerAddress: `http://127.0.0.1:${options.e2ePort}`,
67
+ webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${options.e2eWebServerTarget} ${options.projectName}`,
68
68
  addPlugin: options.addPlugin,
69
69
  });
70
70
  }
@@ -31,6 +31,7 @@ function createApplicationFiles(host, options) {
31
31
  styleContent: (0, create_application_files_helpers_1.createStyleRules)(),
32
32
  pageStyleContent: `.page {}`,
33
33
  stylesExt: options.style === 'less' ? options.style : 'css',
34
+ style: options.style === 'tailwind' ? 'css' : options.style,
34
35
  };
35
36
  const generatedAppFilePath = options.src
36
37
  ? (0, path_1.join)(options.appProjectRoot, 'src')
@@ -6,6 +6,9 @@ export interface NormalizedSchema extends Schema {
6
6
  outputPath: string;
7
7
  e2eProjectName: string;
8
8
  e2eProjectRoot: string;
9
+ e2eWebServerAddress: string;
10
+ e2eWebServerTarget: string;
11
+ e2ePort: number;
9
12
  parsedTags: string[];
10
13
  fileName: string;
11
14
  styledModule: null | string;
@@ -20,8 +20,30 @@ async function normalizeOptions(host, options) {
20
20
  const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
21
21
  nxJson.useInferencePlugins !== false;
22
22
  options.addPlugin ??= addPlugin;
23
+ let e2eWebServerTarget = options.addPlugin ? 'start' : 'serve';
24
+ if (options.addPlugin) {
25
+ if (nxJson.plugins) {
26
+ for (const plugin of nxJson.plugins) {
27
+ if (typeof plugin === 'object' &&
28
+ plugin.plugin === '@nx/next/plugin' &&
29
+ plugin.options.startTargetName) {
30
+ e2eWebServerTarget = plugin.options
31
+ .startTargetName;
32
+ }
33
+ }
34
+ }
35
+ }
36
+ let e2ePort = options.addPlugin ? 3000 : 4200;
37
+ if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
38
+ (nxJson.targetDefaults?.[e2eWebServerTarget].options?.port ||
39
+ nxJson.targetDefaults?.[e2eWebServerTarget].options?.env?.PORT)) {
40
+ e2ePort =
41
+ nxJson.targetDefaults?.[e2eWebServerTarget].options?.port ||
42
+ nxJson.targetDefaults?.[e2eWebServerTarget].options?.env?.PORT;
43
+ }
23
44
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
24
45
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
46
+ const e2eWebServerAddress = `http://localhost:${e2ePort}`;
25
47
  const name = (0, devkit_1.names)(options.name).fileName;
26
48
  const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
27
49
  const parsedTags = options.tags
@@ -30,7 +52,7 @@ async function normalizeOptions(host, options) {
30
52
  const fileName = 'index';
31
53
  const appDir = options.appDir ?? true;
32
54
  const src = options.src ?? true;
33
- const styledModule = /^(css|scss|less)$/.test(options.style)
55
+ const styledModule = /^(css|scss|less|tailwind)$/.test(options.style)
34
56
  ? null
35
57
  : options.style;
36
58
  (0, assertion_1.assertValidStyle)(options.style);
@@ -41,6 +63,9 @@ async function normalizeOptions(host, options) {
41
63
  appProjectRoot,
42
64
  e2eProjectName,
43
65
  e2eProjectRoot,
66
+ e2eWebServerAddress,
67
+ e2eWebServerTarget,
68
+ e2ePort,
44
69
  e2eTestRunner: options.e2eTestRunner || 'cypress',
45
70
  fileName,
46
71
  linter: options.linter || eslint_1.Linter.EsLint,
@@ -46,6 +46,10 @@
46
46
  "value": "less",
47
47
  "label": "LESS [ https://lesscss.org ]"
48
48
  },
49
+ {
50
+ "value": "tailwind",
51
+ "label": "tailwind [ https://tailwindcss.com/ ]"
52
+ },
49
53
  {
50
54
  "value": "styled-components",
51
55
  "label": "styled-components [ https://styled-components.com ]"