Merge branch 'optimize' into shigusegubu-themes3

This commit is contained in:
Henry Jameson 2026-06-03 06:05:39 +03:00
commit 3e5054d1ec
2 changed files with 15 additions and 22 deletions

View file

@ -27,12 +27,13 @@ export const devSwPlugin = ({ swSrc, swDest, transformSW, alias }) => {
Object.entries(alias).forEach(([source, dest]) => { Object.entries(alias).forEach(([source, dest]) => {
esbuildAlias[source] = dest.startsWith('/') ? projectRoot + dest : dest esbuildAlias[source] = dest.startsWith('/') ? projectRoot + dest : dest
}) })
let localConfig
return { return {
name: 'dev-sw-plugin', name: 'dev-sw-plugin',
apply: 'serve', apply: 'serve',
configResolved() { configResolved(config) {
/* no-op */ localConfig = config
}, },
resolveId(id) { resolveId(id) {
const name = id.startsWith('/') ? id.slice(1) : id const name = id.startsWith('/') ? id.slice(1) : id
@ -57,9 +58,13 @@ export const devSwPlugin = ({ swSrc, swDest, transformSW, alias }) => {
* https://bugzilla.mozilla.org/show_bug.cgi?id=1360870 * https://bugzilla.mozilla.org/show_bug.cgi?id=1360870
*/ */
async transform(code, id) { async transform(code, id) {
if (id === swFullSrc && transformSW) { if (id === swFullSrc) {
const res = await esbuild.build({ const res = await esbuild.build({
entryPoints: [swSrc], entryPoints: [swSrc],
define: {
'process.env': JSON.stringify(localConfig.define['process.env']),
'COMMIT_HASH': JSON.stringify(localConfig.define['COMMIT_HASH']),
},
bundle: true, bundle: true,
write: false, write: false,
outfile: 'sw-pleroma.js', outfile: 'sw-pleroma.js',
@ -135,16 +140,17 @@ export const buildSwPlugin = ({ swSrc, swDest }) => {
publicDir: false, publicDir: false,
build: { build: {
...resolvedConfig.build, ...resolvedConfig.build,
lib: {
entry: swSrc,
formats: ['iife'],
name: 'sw_pleroma',
},
emptyOutDir: false, emptyOutDir: false,
rolldownOptions: { rolldownOptions: {
input: {
main: swSrc
},
context: 'self',
output: { output: {
entryFileNames: swDest, entryFileNames: swDest,
}, codeSplitting: false,
format: 'iife',
}
}, },
}, },
configFile: false, configFile: false,

View file

@ -165,18 +165,6 @@ export default defineConfig(async ({ mode, command }) => {
}), }),
...(mode === 'test' ? [mswPlugin()] : []), ...(mode === 'test' ? [mswPlugin()] : []),
], ],
optimizeDeps: {
// For unknown reasons, during vitest, vite will re-optimize the following
// deps, causing the test to reload, so add them here so that it will not
// reload during tests
include: [
'custom-event-polyfill',
'vue-i18n',
'@ungap/event-target',
'body-scroll-lock',
'@kazvmoe-infra/pinch-zoom-element',
],
},
css: { css: {
devSourcemap: true, devSourcemap: true,
transformer: 'lightningcss', transformer: 'lightningcss',
@ -210,7 +198,6 @@ export default defineConfig(async ({ mode, command }) => {
main: 'index.html', main: 'index.html',
}, },
output: { output: {
inlineDynamicImports: false,
entryFileNames(chunkInfo) { entryFileNames(chunkInfo) {
const id = chunkInfo.facadeModuleId const id = chunkInfo.facadeModuleId
if (id.endsWith(swSrc)) { if (id.endsWith(swSrc)) {