diff --git a/e2e/webpack/src/__snapshots__/webpack.legacy.test.ts.snap b/e2e/webpack/src/__snapshots__/webpack.legacy.test.ts.snap
index 9852a63a9406b6..31219273146df9 100644
--- a/e2e/webpack/src/__snapshots__/webpack.legacy.test.ts.snap
+++ b/e2e/webpack/src/__snapshots__/webpack.legacy.test.ts.snap
@@ -88,6 +88,14 @@ exports[`Webpack Plugin (legacy) ConvertConfigToWebpackPlugin, should convert wi
"lint": {
"executor": "@nx/eslint:lint"
},
+ "serve-static": {
+ "executor": "@nx/web:file-server",
+ "dependsOn": ["build"],
+ "options": {
+ "buildTarget": "app3224373:build",
+ "spa": true
+ }
+ },
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
diff --git a/e2e/webpack/src/webpack.legacy.test.ts b/e2e/webpack/src/webpack.legacy.test.ts
index 080ea696740c45..fc07db05c327f8 100644
--- a/e2e/webpack/src/webpack.legacy.test.ts
+++ b/e2e/webpack/src/webpack.legacy.test.ts
@@ -2,6 +2,7 @@ import {
checkFilesExist,
cleanupProject,
killProcessAndPorts,
+ listFiles,
newProject,
readFile,
runCLI,
@@ -113,17 +114,17 @@ describe('Webpack Plugin (legacy)', () => {
updateFile(
`${appName}/src/main.ts`,
`
- document.querySelector('proj-root').innerHTML = '
Welcome
';
+ document.querySelector('proj-root')!.innerHTML = 'Welcome
';
`
);
updateFile(
`${appName}/webpack.config.js`,
`
const { join } = require('path');
- const {NxWebpackPlugin} = require('@nx/webpack');
+ const {NxAppWebpackPlugin} = require('@nx/webpack/app-plugin');
module.exports = {
output: {
- path: join(__dirname, '../dist/app9524918'),
+ path: join(__dirname, '../dist/${appName}'),
},
plugins: [
new NxAppWebpackPlugin({
diff --git a/packages/react/src/generators/application/lib/add-e2e.ts b/packages/react/src/generators/application/lib/add-e2e.ts
index a6f4617d0d2e10..5da77e12ce49a2 100644
--- a/packages/react/src/generators/application/lib/add-e2e.ts
+++ b/packages/react/src/generators/application/lib/add-e2e.ts
@@ -16,19 +16,18 @@ export async function addE2e(
tree: Tree,
options: NormalizedSchema
): Promise {
+ const hasNxBuildPlugin =
+ (options.bundler === 'webpack' && hasWebpackPlugin(tree)) ||
+ (options.bundler === 'vite' && hasVitePlugin(tree));
+ if (!hasNxBuildPlugin) {
+ await webStaticServeGenerator(tree, {
+ buildTarget: `${options.projectName}:build`,
+ targetName: 'serve-static',
+ spa: true,
+ });
+ }
switch (options.e2eTestRunner) {
case 'cypress': {
- const hasNxBuildPlugin =
- (options.bundler === 'webpack' && hasWebpackPlugin(tree)) ||
- (options.bundler === 'vite' && hasVitePlugin(tree));
- if (!hasNxBuildPlugin) {
- await webStaticServeGenerator(tree, {
- buildTarget: `${options.projectName}:build`,
- targetName: 'serve-static',
- spa: true,
- });
- }
-
const { configurationGenerator } = ensurePackage<
typeof import('@nx/cypress')
>('@nx/cypress', nxVersion);
diff --git a/packages/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts
index 0d161a2a559a6e..5b0df944b12fc8 100644
--- a/packages/web/src/generators/application/application.ts
+++ b/packages/web/src/generators/application/application.ts
@@ -42,6 +42,7 @@ import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-com
import { VitePluginOptions } from '@nx/vite/src/plugins/plugin';
import { WebpackPluginOptions } from '@nx/webpack/src/plugins/plugin';
import { hasVitePlugin } from '../../utils/has-vite-plugin';
+import staticServeConfiguration from '../static-serve/static-serve-configuration';
interface NormalizedSchema extends Schema {
projectName: string;
@@ -367,10 +368,16 @@ export async function applicationGeneratorInternal(host: Tree, schema: Schema) {
tasks.push(lintTask);
}
+ const hasNxBuildPlugin =
+ (options.bundler === 'webpack' && hasWebpackPlugin(host)) ||
+ (options.bundler === 'vite' && hasVitePlugin(host));
+ if (!hasNxBuildPlugin) {
+ await staticServeConfiguration(host, {
+ buildTarget: `${options.projectName}:build`,
+ spa: true,
+ });
+ }
if (options.e2eTestRunner === 'cypress') {
- const hasNxBuildPlugin =
- (options.bundler === 'webpack' && hasWebpackPlugin(host)) ||
- (options.bundler === 'vite' && hasVitePlugin(host));
const { configurationGenerator } = ensurePackage<
typeof import('@nx/cypress')
>('@nx/cypress', nxVersion);