Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack): ensure webpack config is always at the latest version when running in the daemon #20618

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/webpack/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ async function createWebpackTargets(
const namedInputs = getNamedInputs(projectRoot, context);
const webpackConfig = resolveUserDefinedWebpackConfig(
join(context.workspaceRoot, configFilePath),
getRootTsConfigPath()
getRootTsConfigPath(),
true
);
const webpackOptions = await readWebpackOptions(webpackConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@ import { registerTsProject } from '@nx/js/src/internal';

export function resolveUserDefinedWebpackConfig(
path: string,
tsConfig: string
tsConfig: string,
/** Skip require cache and return latest content */
reload = false
) {
if (reload) {
// Clear cache if the path is in the cache
if (require.cache[path]) {
// Clear all entries because config may import other modules
for (const k of Object.keys(require.cache)) {
delete require.cache[k];
}
}
}

// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
if (!/\.(ts|mts|cts)$/.test(path)) {
Expand Down