Skip to content

Commit

Permalink
fix: add browsers list config to cache key (#6976)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Oct 8, 2024
1 parent 0b4e0cc commit b0eb09d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/gorgeous-lemons-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ice/webpack-config': patch
'@ice/shared-config': patch
---

fix: mark browserslist config to cache key
3 changes: 2 additions & 1 deletion packages/shared-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import compilationPlugin, { isSupportedFeature, getJsxTransformOptions } from './unPlugins/compilation.js';
import compilationPlugin, { isSupportedFeature, getJsxTransformOptions, getSupportedBrowsers } from './unPlugins/compilation.js';
import compileExcludes, { SKIP_COMPILE as skipCompilePackages } from './compileExcludes.js';
import getCompilerPlugins from './getCompilerPlugins.js';
import getDefineVars from './getDefineVars.js';
Expand All @@ -19,4 +19,5 @@ export {
getPostcssOpts,
getAliasWithRoot,
getDevtoolValue,
getSupportedBrowsers,
};
4 changes: 2 additions & 2 deletions packages/shared-config/src/unPlugins/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ export function getJsxTransformOptions({
return commonOptions;
}

function getSupportedBrowsers(
export function getSupportedBrowsers(
dir: string,
isDevelopment: boolean,
): string[] | undefined {
let browsers: any;
let browsers: string[];
try {
browsers = browserslist.loadConfig({
path: dir,
Expand Down
7 changes: 5 additions & 2 deletions packages/webpack-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import { createRequire } from 'module';
import crypto from 'crypto';
import fg from 'fast-glob';
import ReactRefreshWebpackPlugin from '@ice/bundles/compiled/@pmmmwh/react-refresh-webpack-plugin/lib/index.js';
import bundleAnalyzer from '@ice/bundles/compiled/webpack-bundle-analyzer/index.js';
Expand All @@ -11,7 +12,7 @@ import ESlintPlugin from '@ice/bundles/compiled/eslint-webpack-plugin/index.js';
import CopyPlugin from '@ice/bundles/compiled/copy-webpack-plugin/index.js';
import type { NormalModule, Compiler, Configuration } from 'webpack';
import type webpack from 'webpack';
import { compilationPlugin, compileExcludes, getCompilerPlugins, getDefineVars, getAliasWithRoot, getDevtoolValue } from '@ice/shared-config';
import { compilationPlugin, compileExcludes, getCompilerPlugins, getDefineVars, getAliasWithRoot, getDevtoolValue, getSupportedBrowsers } from '@ice/shared-config';
import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types.js';
import configAssets from './config/assets.js';
import configCss from './config/css.js';
Expand Down Expand Up @@ -152,6 +153,8 @@ export function getWebpackConfig(options: GetWebpackConfigOptions): Configuratio
module: true,
}, minimizerOptions);

const supportBrowsers = getSupportedBrowsers(rootDir, dev);
const browsersMD5 = supportBrowsers ? crypto.createHash('md5').update(supportBrowsers.join('')).digest('hex') : '';
const compilation = compilationPlugin({
rootDir,
cacheDir,
Expand Down Expand Up @@ -257,7 +260,7 @@ export function getWebpackConfig(options: GetWebpackConfigOptions): Configuratio
} as Configuration['optimization'],
cache: enableCache ? {
type: 'filesystem',
version: `${process.env.__ICE_VERSION__}|${userConfigHash}`,
version: `${process.env.__ICE_VERSION__}|${userConfigHash}|${browsersMD5}`,
buildDependencies: { config: [path.join(rootDir, 'package.json')] },
cacheDirectory: path.join(cacheDir, 'webpack'),
} : false,
Expand Down

0 comments on commit b0eb09d

Please sign in to comment.