Skip to content

Commit

Permalink
fix(webpack): ensure webpack config is always at the latest version w…
Browse files Browse the repository at this point in the history
…hen running in the daemon (#20618)
  • Loading branch information
jaysoo committed Dec 6, 2023
1 parent 3493c78 commit 7ffc328
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 7ffc328

Please sign in to comment.