fix: don't invalidate framework chunk when a new asset is added

pull/5297/head
Divyansh Singh 2 months ago
parent 1ade7bd422
commit c0e2e18094

@ -16,7 +16,7 @@ import { escapeRegExp, sanitizeFileName, slash } from '../shared'
import { task } from '../utils/task'
import { buildMPAClient } from './buildMPAClient'
// https://github.com/vitejs/vite/blob/d2aa0969ee316000d3b957d7e879f001e85e369e/packages/vite/src/node/plugins/splitVendorChunk.ts#L14
// https://github.com/vitejs/vite/blob/a55d0b34400e3360c4100d05e422ae9cf10fa07b/packages/vite/src/node/constants.ts#L50
const CSS_LANGS_RE =
/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
@ -125,35 +125,24 @@ export async function bundle(
codeSplitting: {
groups: [
{
name(
id: string,
ctx: Pick<Rolldown.PluginContext, 'getModuleInfo'>
) {
// ctx.getModuleInfo must not be called detached from ctx
const getModuleInfo: Rolldown.GetModuleInfo = (
moduleId
) => ctx.getModuleInfo(moduleId)
name(id, ctx) {
const getModuleInfo = ctx.getModuleInfo.bind(ctx)
// avoid emitting multiple files for assets
// see: https://github.com/rolldown/rolldown/issues/4246
if (getModuleInfo(id)?.meta['vite:asset']) {
return 'assets'
}
// move known framework code into a stable chunk so that
// custom theme changes do not invalidate hash for all pages
if (
id.startsWith('\0vite') ||
getModuleInfo(id)?.meta['vite:asset']
) {
return 'framework'
}
if (id.includes('plugin-vue:export-helper')) {
return 'framework'
}
if (
id.includes(`${clientDir}/app`) &&
id !== `${clientDir}/app/index.js`
) {
return 'framework'
}
if (
isEagerChunk(id, getModuleInfo) &&
/@vue\/(runtime|shared|reactivity)/.test(id)
id.includes('plugin-vue:export-helper') ||
(id.includes(`${clientDir}/app`) &&
id !== `${clientDir}/app/index.js`) ||
(isEagerChunk(id, getModuleInfo) &&
/@vue\/(runtime|shared|reactivity)/.test(id))
) {
return 'framework'
}

@ -2,7 +2,7 @@ import { isBooleanAttr } from '@vue/shared'
import fs from 'node:fs'
import { mkdir, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { minify, normalizePath, type Rolldown } from 'vite'
import { minifySync, normalizePath, type Rolldown } from 'vite'
import { version } from '../../../package.json'
import type { SiteConfig } from '../config'
import {
@ -246,7 +246,7 @@ async function renderHead(head: HeadConfig[]): Promise<string> {
tag === 'script' &&
(attrs.type === undefined || attrs.type.includes('javascript'))
) {
innerHTML = await minifyScript(innerHTML, 'inline-script.js')
innerHTML = minifySync('inline-script.js', innerHTML).code
}
return `${openTag}${innerHTML}</${tag}>`
} else {
@ -266,10 +266,6 @@ function renderAttrs(attrs: Record<string, string>): string {
.join('')
}
async function minifyScript(code: string, filename: string): Promise<string> {
return (await minify(filename, code)).code.trim()
}
function filterOutHeadDescription(head: HeadConfig[] = []) {
return head.filter(([type, attrs]) => {
return !(type === 'meta' && attrs?.name === 'description')

Loading…
Cancel
Save