Skip to content

Commit

Permalink
fix(webpack): support standard webpack config with @nx/webpack:dev-se…
Browse files Browse the repository at this point in the history
…rver (#22660)

(cherry picked from commit 4fdf862)
  • Loading branch information
jaysoo authored and FrozenPandaz committed Apr 5, 2024
1 parent 042212e commit 1b80d01
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions e2e/webpack/src/webpack.legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
newProject,
runCLI,
runCommandUntil,
runE2ETests,
uniq,
updateFile,
} from '@nx/e2e/utils';
Expand Down Expand Up @@ -102,4 +103,47 @@ describe('Webpack Plugin (legacy)', () => {
checkFilesExist(`dist/${appName}/styles.css`);
}).toThrow();
});

it('should support standard webpack config with executors', () => {
const appName = uniq('app');
runCLI(
`generate @nx/web:app ${appName} --bundler webpack --e2eTestRunner=playwright`
);
updateFile(
`${appName}/src/main.ts`,
`
document.querySelector('proj-root').innerHTML = '<h1>Welcome</h1>';
`
);
updateFile(
`${appName}/webpack.config.js`,
`
const { join } = require('path');
const {NxWebpackPlugin} = require('@nx/webpack');
module.exports = {
output: {
path: join(__dirname, '../dist/app9524918'),
},
plugins: [
new NxWebpackPlugin({
main: './src/main.ts',
compiler: 'tsc',
index: './src/index.html',
tsConfig: './tsconfig.app.json',
})
]
};
`
);

expect(() => {
runCLI(`build ${appName} --outputHashing none`);
}).not.toThrow();

if (runE2ETests()) {
expect(() => {
runCLI(`e2e ${appName}-e2e`);
}).not.toThrow();
}
});
});
4 changes: 4 additions & 0 deletions packages/webpack/src/executors/dev-server/dev-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export async function* devServerExecutor(
configuration: serveOptions.buildTarget.split(':')[2],
}
);
} else if (userDefinedWebpackConfig) {
// New behavior, we want the webpack config to export object
config = userDefinedWebpackConfig;
config.devServer ??= devServer;
}
}

Expand Down

0 comments on commit 1b80d01

Please sign in to comment.