fix(webpack): handle relative paths for additionalEntryPath (#27885)
The `NxAppWebpackPlugin` does not support relative paths in
`additionalEntryPoints`.
So this will fail:
```js
new NxAppWebpackPlugin({
...
additionalEntryPoints: ['.src/foo.ts']
```
The resolved path is relative to workspace root when it should be
project root.
<!-- 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
Build will fail.
## Expected Behavior
Build should work.
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
Fixes #
This commit is contained in:
parent
43eaa5a348
commit
d8cb932422
@ -132,8 +132,12 @@ describe('Webpack Plugin', () => {
|
||||
|
||||
it('should be able to build with NxWebpackPlugin and a standard webpack config file', () => {
|
||||
const appName = uniq('app');
|
||||
runCLI(`generate @nx/web:app ${appName} --bundler webpack`);
|
||||
runCLI(
|
||||
`generate @nx/web:app ${appName} --bundler webpack --directory=apps/${appName} --projectNameAndRootFormat=as-provided`
|
||||
);
|
||||
updateFile(`apps/${appName}/src/main.ts`, `console.log('Hello');\n`);
|
||||
updateFile(`apps/${appName}/src/foo.ts`, `console.log('Foo');\n`);
|
||||
updateFile(`apps/${appName}/src/bar.ts`, `console.log('Bar');\n`);
|
||||
|
||||
updateFile(
|
||||
`apps/${appName}/webpack.config.js`,
|
||||
@ -144,13 +148,20 @@ describe('Webpack Plugin', () => {
|
||||
module.exports = {
|
||||
target: 'node',
|
||||
output: {
|
||||
path: path.join(__dirname, '../../dist/${appName}')
|
||||
path: path.join(__dirname, '../../dist/apps/${appName}')
|
||||
},
|
||||
plugins: [
|
||||
new NxAppWebpackPlugin({
|
||||
compiler: 'tsc',
|
||||
main: 'apps/${appName}/src/main.ts',
|
||||
tsConfig: 'apps/${appName}/tsconfig.app.json',
|
||||
main: './src/main.ts',
|
||||
additionalEntryPoints: [
|
||||
'./src/foo.ts',
|
||||
{
|
||||
entryName: 'bar',
|
||||
entryPath: './src/bar.ts',
|
||||
}
|
||||
],
|
||||
tsConfig: './tsconfig.app.json',
|
||||
outputHashing: 'none',
|
||||
optimization: false,
|
||||
})
|
||||
@ -160,8 +171,9 @@ describe('Webpack Plugin', () => {
|
||||
|
||||
runCLI(`build ${appName}`);
|
||||
|
||||
let output = runCommand(`node dist/${appName}/main.js`);
|
||||
expect(output).toMatch(/Hello/);
|
||||
expect(runCommand(`node dist/apps/${appName}/main.js`)).toMatch(/Hello/);
|
||||
expect(runCommand(`node dist/apps/${appName}/foo.js`)).toMatch(/Foo/);
|
||||
expect(runCommand(`node dist/apps/${appName}/bar.js`)).toMatch(/Bar/);
|
||||
}, 500_000);
|
||||
|
||||
it('should bundle in NX_PUBLIC_ environment variables', () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { basename, dirname, join, relative, resolve } from 'path';
|
||||
import { basename, dirname, join, parse, relative, resolve } from 'path';
|
||||
import { statSync } from 'fs';
|
||||
import {
|
||||
normalizePath,
|
||||
@ -204,6 +204,18 @@ function normalizeRelativePaths(
|
||||
for (const [fieldName, fieldValue] of Object.entries(options)) {
|
||||
if (isRelativePath(fieldValue)) {
|
||||
options[fieldName] = join(projectRoot, fieldValue);
|
||||
} else if (fieldName === 'additionalEntryPoints') {
|
||||
for (let i = 0; i < fieldValue.length; i++) {
|
||||
const v = fieldValue[i];
|
||||
if (isRelativePath(v)) {
|
||||
fieldValue[i] = {
|
||||
entryName: parse(v).name,
|
||||
entryPath: join(projectRoot, v),
|
||||
};
|
||||
} else if (isRelativePath(v.entryPath)) {
|
||||
v.entryPath = join(projectRoot, v.entryPath);
|
||||
}
|
||||
}
|
||||
} else if (Array.isArray(fieldValue)) {
|
||||
for (let i = 0; i < fieldValue.length; i++) {
|
||||
if (isRelativePath(fieldValue[i])) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user