mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
chore(core): update webpack hash logic (#3308)
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import { hash } from './utils.js';
|
|
||||||
|
|
||||||
function testPackageName(regexp: RegExp): (module: any) => boolean {
|
function testPackageName(regexp: RegExp): (module: any) => boolean {
|
||||||
return (module: any) =>
|
return (module: any) =>
|
||||||
module.nameForCondition && regexp.test(module.nameForCondition());
|
module.nameForCondition && regexp.test(module.nameForCondition());
|
||||||
@@ -13,7 +11,7 @@ export const productionCacheGroups = {
|
|||||||
const name =
|
const name =
|
||||||
module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)?.[1] ??
|
module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)?.[1] ??
|
||||||
'unknown';
|
'unknown';
|
||||||
return `npm-async-${hash(name)}`;
|
return `npm-async-${name}`;
|
||||||
},
|
},
|
||||||
priority: Number.MAX_SAFE_INTEGER,
|
priority: Number.MAX_SAFE_INTEGER,
|
||||||
chunks: 'async' as const,
|
chunks: 'async' as const,
|
||||||
|
|||||||
@@ -84,10 +84,13 @@ export const createConfiguration: (
|
|||||||
module: true,
|
module: true,
|
||||||
dynamicImport: true,
|
dynamicImport: true,
|
||||||
},
|
},
|
||||||
filename: 'js/[name].js',
|
filename:
|
||||||
|
buildFlags.mode === 'production'
|
||||||
|
? 'js/[name]-[contenthash:8].js'
|
||||||
|
: 'js/[name].js',
|
||||||
// In some cases webpack will emit files starts with "_" which is reserved in web extension.
|
// In some cases webpack will emit files starts with "_" which is reserved in web extension.
|
||||||
chunkFilename: 'js/chunk.[name].js',
|
chunkFilename: 'js/chunk.[name].js',
|
||||||
assetModuleFilename: 'assets/[hash][ext][query]',
|
assetModuleFilename: 'assets/[contenthash:8][ext][query]',
|
||||||
devtoolModuleFilenameTemplate: 'webpack://[namespace]/[resource-path]',
|
devtoolModuleFilenameTemplate: 'webpack://[namespace]/[resource-path]',
|
||||||
hotUpdateChunkFilename: 'hot/[id].[fullhash].js',
|
hotUpdateChunkFilename: 'hot/[id].[fullhash].js',
|
||||||
hotUpdateMainFilename: 'hot/[runtime].[fullhash].json',
|
hotUpdateMainFilename: 'hot/[runtime].[fullhash].json',
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
import { createHash } from 'node:crypto';
|
|
||||||
import type { BuildFlags } from '@affine/cli/config';
|
import type { BuildFlags } from '@affine/cli/config';
|
||||||
|
|
||||||
export function hash(content: string): string {
|
|
||||||
const hash = createHash('sha512');
|
|
||||||
hash.update(content);
|
|
||||||
const pkgHash = hash.digest('hex');
|
|
||||||
return pkgHash.substring(0, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function computeCacheKey(buildFlags: BuildFlags) {
|
export function computeCacheKey(buildFlags: BuildFlags) {
|
||||||
return [
|
return [
|
||||||
'1',
|
'1',
|
||||||
|
|||||||
Reference in New Issue
Block a user