-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The `serve-static` target is being added in the `add-e2e` file, however, it has uses beyond e2e. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The `serve-static` target should be added with more intention ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #27854
- Loading branch information
Showing
4 changed files
with
56 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/angular/src/generators/application/lib/add-serve-static-target.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Tree } from '@nx/devkit'; | ||
import type { NormalizedSchema } from './normalized-schema'; | ||
import { | ||
addDependenciesToPackageJson, | ||
joinPathFragments, | ||
readProjectConfiguration, | ||
updateProjectConfiguration, | ||
} from '@nx/devkit'; | ||
import { nxVersion } from '../../../utils/versions'; | ||
import { getInstalledAngularVersionInfo } from '../../utils/version-utils'; | ||
|
||
export function addServeStaticTarget( | ||
tree: Tree, | ||
options: NormalizedSchema, | ||
port: number | ||
) { | ||
addFileServerTarget(tree, options, 'serve-static', port); | ||
} | ||
|
||
function addFileServerTarget( | ||
tree: Tree, | ||
options: NormalizedSchema, | ||
targetName: string, | ||
e2ePort: number | ||
) { | ||
if (!options.skipPackageJson) { | ||
addDependenciesToPackageJson(tree, {}, { '@nx/web': nxVersion }); | ||
} | ||
|
||
const { major: angularMajorVersion } = getInstalledAngularVersionInfo(tree); | ||
const isUsingApplicationBuilder = | ||
angularMajorVersion >= 17 && options.bundler === 'esbuild'; | ||
|
||
const projectConfig = readProjectConfiguration(tree, options.name); | ||
projectConfig.targets[targetName] = { | ||
executor: '@nx/web:file-server', | ||
options: { | ||
buildTarget: `${options.name}:build`, | ||
port: e2ePort, | ||
staticFilePath: isUsingApplicationBuilder | ||
? joinPathFragments(options.outputPath, 'browser') | ||
: undefined, | ||
spa: true, | ||
}, | ||
}; | ||
updateProjectConfiguration(tree, options.name, projectConfig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters