Skip to content

Commit

Permalink
Merge pull request #213 from core-ds/feat/cache-invalidation
Browse files Browse the repository at this point in the history
feat(webpack): invalidate caches on overrides and presets changes
  • Loading branch information
heymdall-legal authored Apr 25, 2024
2 parents 5fb5913 + 6eff863 commit bc8cb61
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-numbers-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'arui-scripts': minor
---

Улучшен механизм инвалидации кешей вебпака
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import { tryResolve } from '../util/resolve';

export function readConfigFile(cwd: string) {
const appConfigPath = tryResolve(path.join(cwd, '/arui-scripts.config'));
const appConfigPath = getConfigFilePath(cwd);

if (appConfigPath) {
// Мы не можем использовать импорты, нам нужен именно require, потому что мы не знаем заранее не только путь до файла,
Expand All @@ -22,3 +22,7 @@ export function readConfigFile(cwd: string) {

return null;
}

export function getConfigFilePath(cwd: string) {
return tryResolve(path.join(cwd, '/arui-scripts.config'));
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export function updateWithPresets(config: AppConfigs, context: AppContext) {
return config;
}

const presetsConfigPath = tryResolve(`${config.presets}/arui-scripts.config`, {
paths: [context.cwd],
});
const presetsConfigPath = getPresetsConfigPath(config, context.cwd);
const presetsOverridesPath = tryResolve(`${config.presets}/arui-scripts.overrides`, {
paths: [context.cwd],
});
Expand All @@ -37,3 +35,9 @@ export function updateWithPresets(config: AppConfigs, context: AppContext) {

return config;
}

export function getPresetsConfigPath(config: AppConfigs, cwd: string) {
return tryResolve(`${config.presets}/arui-scripts.config`, {
paths: [cwd],
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import configs from '../app-configs';
import { getConfigFilePath } from '../app-configs/read-config-file';
import { getPresetsConfigPath } from '../app-configs/update-with-presets';

export function getWebpackCacheDependencies(): Record<string, string[]> {
return {
overrides: configs.overridesPath,
appConfigs: [
getConfigFilePath(configs.cwd),
getPresetsConfigPath(configs, configs.cwd),
].filter(Boolean) as string[],
}
}
2 changes: 2 additions & 0 deletions packages/arui-scripts/src/configs/webpack.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { patchMainWebpackConfigForModules, patchWebpackConfigForCompat } from '.
import postcssConf from './postcss';
import { processAssetsPluginOutput } from './process-assets-plugin-output';
import { AruiRuntimePlugin, getInsertCssRuntimeMethod } from '../plugins/arui-runtime';
import { getWebpackCacheDependencies } from './util/get-webpack-cache-dependencies';

const PnpWebpackPlugin = require('pnp-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
Expand Down Expand Up @@ -239,6 +240,7 @@ export const createSingleClientWebpackConfig = (
type: 'filesystem',
buildDependencies: {
config: [__filename],
...getWebpackCacheDependencies(),
},
}
: false,
Expand Down
2 changes: 2 additions & 0 deletions packages/arui-scripts/src/configs/webpack.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { babelDependencies } from './babel-dependencies';
import babelConf from './babel-server';
import postcssConf from './postcss';
import { serverExternalsExemptions } from './server-externals-exemptions';
import { getWebpackCacheDependencies } from './util/get-webpack-cache-dependencies';

const ReloadServerPlugin = require('../plugins/reload-server-webpack-plugin');
const WatchMissingNodeModulesPlugin = require('../plugins/watch-missing-node-modules-plugin');
Expand Down Expand Up @@ -71,6 +72,7 @@ export const createServerConfig = (mode: 'dev' | 'prod'): Configuration => ({
name: 'server',
buildDependencies: {
config: [__filename],
...getWebpackCacheDependencies(),
},
}
: false,
Expand Down

0 comments on commit bc8cb61

Please sign in to comment.