Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add browsers list config to cache key #6976

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading