Skip to content

Commit 40a3c21

Browse files
committed
fix: rebuild dll when extraVendors changed or project changed
1 parent 7cc1705 commit 40a3c21

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/built-in-plugins/command-dev/plugin/dll.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import * as fs from 'fs-extra';
22
import * as path from 'path';
33
import * as webpack from 'webpack';
44
import { globalState } from '../../../utils/global-state';
5-
import { hasNodeModules, hasNodeModulesModified } from '../../../utils/project-helper';
5+
import {
6+
hasNodeModules,
7+
hasNodeModulesModified,
8+
hasExtraVendorsChanged,
9+
hasPackageChanged,
10+
} from '../../../utils/project-helper';
611
import getWebpackDllConfig from './webpack-dll-config';
712

813
export const dllFileName = 'main.dll.js';
@@ -48,10 +53,15 @@ function runCompiler(compiler: webpack.Compiler) {
4853
}
4954

5055
/**
51-
* Bundle dlls if node_modules changed, or dlls not exist.
56+
* Bundle dlls when node_modules changed, dlls not exist, extraDll changed, or package to dev changed;
5257
*/
5358
export async function bundleDlls() {
54-
if ((hasNodeModules() && hasNodeModulesModified()) || !fs.existsSync(path.join(dllOutPath, dllFileName))) {
59+
if (
60+
hasPackageChanged() ||
61+
hasExtraVendorsChanged() ||
62+
(hasNodeModules() && hasNodeModulesModified()) ||
63+
!fs.existsSync(path.join(dllOutPath, dllFileName))
64+
) {
5565
await runDllWebpack({ dllOutPath, dllFileName, dllMainfestName });
5666
}
5767
}

src/utils/project-helper.ts

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
3+
import * as yargs from 'yargs';
34
import { globalState } from './global-state';
45
import * as projectState from './project-state';
56

@@ -14,6 +15,18 @@ export const hasNodeModulesModified = () => {
1415
return hasChanged(key, nextModifiedTime);
1516
};
1617

18+
export const hasExtraVendorsChanged = () => {
19+
const key = 'extraVendors';
20+
const newExtraVendors = JSON.stringify(globalState.sourceConfig.extraVendors ?? []);
21+
return hasChanged(key, newExtraVendors);
22+
};
23+
24+
export const hasPackageChanged = () => {
25+
const key = 'package';
26+
const newPackage = yargs.argv.package as string;
27+
return hasChanged(key, newPackage);
28+
};
29+
1730
function hasChanged(key: string, nextValue: string) {
1831
const previewValue = projectState.get(key);
1932
if (!previewValue) {

0 commit comments

Comments
 (0)