fix(core): remove hash prefix from cdn path (#5509)

The hash prefix will cause cache invalidate during deployment
It's for debug purpose but I forgot to remove it
This commit is contained in:
LongYinan
2024-01-18 03:50:24 +00:00
parent 943ede4ffd
commit aa437bcd35
3 changed files with 21 additions and 21 deletions

View File

@@ -1,24 +1,11 @@
import { join } from 'node:path';
import { execSync } from 'node:child_process';
import { readFile } from 'node:fs/promises';
import type { PutObjectCommandInput } from '@aws-sdk/client-s3';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { once } from 'lodash-es';
import { lookup } from 'mime-types';
import type { Compiler, WebpackPluginInstance } from 'webpack';
export const gitShortHash = once(() => {
const { GITHUB_SHA } = process.env;
if (GITHUB_SHA) {
return GITHUB_SHA.substring(0, 9);
}
const sha = execSync(`git rev-parse --short HEAD`, {
encoding: 'utf-8',
}).trim();
return sha;
});
export const R2_BUCKET =
process.env.R2_BUCKET! ??
(process.env.BUILD_TYPE === 'canary' ? 'assets-dev' : 'assets-prod');
@@ -45,7 +32,7 @@ export class WebpackS3Plugin implements WebpackPluginInstance {
const putObjectCommandOptions: PutObjectCommandInput = {
Body: assetSource,
Bucket: R2_BUCKET,
Key: join(gitShortHash(), asset),
Key: asset,
};
const contentType = lookup(asset);
if (contentType) {