fix(v2): clean generated manifest from previous build so we dont use the wrong one (#2060)

This commit is contained in:
Endi 2019-11-27 23:13:12 +07:00 committed by Yangshun Tay
parent bd5bdb91f7
commit 5adb58380c

View file

@ -57,6 +57,10 @@ export async function build(
// Apply user webpack config. // Apply user webpack config.
const {outDir, generatedFilesDir, plugins} = props; const {outDir, generatedFilesDir, plugins} = props;
const clientManifestPath = path.join(
generatedFilesDir,
'client-manifest.json',
);
let clientConfig: Configuration = merge(createClientConfig(props), { let clientConfig: Configuration = merge(createClientConfig(props), {
plugins: [ plugins: [
// Remove/clean build folders before building bundles. // Remove/clean build folders before building bundles.
@ -65,7 +69,7 @@ export async function build(
cliOptions.bundleAnalyzer && new BundleAnalyzerPlugin(), cliOptions.bundleAnalyzer && new BundleAnalyzerPlugin(),
// Generate client manifests file that will be used for server bundle // Generate client manifests file that will be used for server bundle
new ReactLoadableSSRAddon({ new ReactLoadableSSRAddon({
filename: path.join(generatedFilesDir, 'client-manifest.json'), filename: clientManifestPath,
}), }),
].filter(Boolean) as Plugin[], ].filter(Boolean) as Plugin[],
}); });
@ -104,6 +108,17 @@ export async function build(
); );
}); });
// Make sure generated client-manifest and chunk-map is cleaned first so we don't reuse the one from prevs build
const chunkManifestPath = path.join(generatedFilesDir, 'chunk-map.json');
await Promise.all(
[clientManifestPath, chunkManifestPath].map(async manifestPath => {
const manifestExist = await fs.pathExists(manifestPath);
if (manifestExist) {
await fs.unlink(manifestPath);
}
}),
);
// Run webpack to build JS bundle (client) and static html files (server). // Run webpack to build JS bundle (client) and static html files (server).
await compile([clientConfig, serverConfig]); await compile([clientConfig, serverConfig]);