Skip to content

Commit

Permalink
fix: clear webpack cache when env files or headless.config.js changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Aug 25, 2023
1 parent b39ab9a commit ebacd84
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-squids-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@headstartwp/next": patch
---

Fix an annoying bug that would require deleting the .next/cache folder after change headless.config.js or .env files
105 changes: 105 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions packages/next/src/config/withHeadlessConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,29 @@ export function withHeadlessConfig(
setHeadstartWPConfig(${JSON.stringify(headlessConfig)});
`;

// clear webpack cache whenever headless.config.js changes or one of the env files
if (Array.isArray(config.cache.buildDependencies.config)) {
const [nextConfigPath] = config.cache.buildDependencies.config;

const headlessConfigPath = path.resolve(nextConfigPath, '../headless.config.js');
const envLocalPath = path.resolve(nextConfigPath, '../.env.local');
const envPath = path.resolve(nextConfigPath, '../.env');
const envDevPath = path.resolve(nextConfigPath, '../.env.development');

if (fs.existsSync(headlessConfigPath)) {
config.cache.buildDependencies.config.push(headlessConfigPath);
config.cache.buildDependencies.config.push(
path.resolve(nextConfigPath, '../.env.local'),
);
}

if (fs.existsSync(envLocalPath)) {
config.cache.buildDependencies.config.push(envLocalPath);
}

if (fs.existsSync(envPath)) {
config.cache.buildDependencies.config.push(envPath);
}

if (fs.existsSync(envDevPath)) {
config.cache.buildDependencies.config.push(envDevPath);
}
}

Expand Down

0 comments on commit ebacd84

Please sign in to comment.