refactor: use __MSG_ placeholders for i18n and remove postcss config
This commit is contained in:
+22
-23
@@ -1,27 +1,27 @@
|
|||||||
import { defineConfig } from 'wxt';
|
import { defineConfig } from 'wxt';
|
||||||
import type { Plugin } from 'vite';
|
import type { Plugin } from 'vite';
|
||||||
import postcssConfig from './postcss.config.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 仅在 HTML 多入口构建(popup / options / sidepanel)中启用 manualChunks 拆分 vendor。
|
|
||||||
* WXT 对 background / content-script 使用 lib 模式(IIFE),该模式不支持 manualChunks。
|
|
||||||
*/
|
|
||||||
function manualChunksForHtmlOnly(): Plugin {
|
function manualChunksForHtmlOnly(): Plugin {
|
||||||
return {
|
return {
|
||||||
name: 'manual-chunks-html-only',
|
name: 'manual-chunks-html-only',
|
||||||
outputOptions(rawOptions) {
|
outputOptions(rawOptions) {
|
||||||
// lib 模式(IIFE)不支持 manualChunks,仅对 ES/CJS 格式启用
|
|
||||||
if (rawOptions.format === 'iife' || rawOptions.format === 'umd') {
|
if (rawOptions.format === 'iife' || rawOptions.format === 'umd') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rawOptions.manualChunks = (id: string) => {
|
|
||||||
if (!id.includes('node_modules')) return;
|
|
||||||
|
|
||||||
// React 核心
|
return {
|
||||||
if (id.includes('/react-dom/') || (id.includes('/react/') && !id.includes('/react-dom/'))) {
|
...rawOptions,
|
||||||
|
manualChunks(id: string): string | void {
|
||||||
|
if (!id.includes('node_modules')) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
id.includes('/react-dom/') ||
|
||||||
|
(id.includes('/react/') && !id.includes('/react-dom/'))
|
||||||
|
) {
|
||||||
return 'vendor-react';
|
return 'vendor-react';
|
||||||
}
|
}
|
||||||
// 国际化
|
|
||||||
if (
|
if (
|
||||||
id.includes('i18next') ||
|
id.includes('i18next') ||
|
||||||
id.includes('react-i18next') ||
|
id.includes('react-i18next') ||
|
||||||
@@ -29,30 +29,32 @@ function manualChunksForHtmlOnly(): Plugin {
|
|||||||
) {
|
) {
|
||||||
return 'vendor-i18n';
|
return 'vendor-i18n';
|
||||||
}
|
}
|
||||||
// QR 相关
|
// 二维码活态感知依赖分流
|
||||||
if (id.includes('qr-scanner') || id.includes('qrious')) {
|
if (id.includes('qr-scanner') || id.includes('qrious')) {
|
||||||
return 'vendor-qr';
|
return 'vendor-qr';
|
||||||
}
|
}
|
||||||
// 拖拽
|
// 拖拽排序高级组件分流
|
||||||
if (id.includes('@dnd-kit')) {
|
if (id.includes('@dnd-kit')) {
|
||||||
return 'vendor-dnd';
|
return 'vendor-dnd';
|
||||||
}
|
}
|
||||||
// Markdown
|
// Markdown 高性能转换引擎分流
|
||||||
if (id.includes('marked')) {
|
if (id.includes('marked')) {
|
||||||
return 'vendor-markdown';
|
return 'vendor-markdown';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://wxt.dev/api/config.html
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
modules: ['@wxt-dev/module-react'],
|
modules: ['@wxt-dev/module-react'],
|
||||||
manifest: {
|
manifest: {
|
||||||
name: 'Testing Tools',
|
name: '__MSG_extName__',
|
||||||
version: '1.0',
|
description: '__MSG_extDescription__',
|
||||||
description: '测试工具',
|
version_name: undefined,
|
||||||
permissions: [
|
permissions: [
|
||||||
'storage',
|
'storage',
|
||||||
'unlimitedStorage',
|
'unlimitedStorage',
|
||||||
@@ -66,7 +68,7 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
host_permissions: ['<all_urls>'],
|
host_permissions: ['<all_urls>'],
|
||||||
action: {
|
action: {
|
||||||
default_title: 'Testing Tools',
|
default_title: '__MSG_extName__',
|
||||||
},
|
},
|
||||||
side_panel: {
|
side_panel: {
|
||||||
default_path: 'entrypoints/sidepanel/index.html',
|
default_path: 'entrypoints/sidepanel/index.html',
|
||||||
@@ -83,10 +85,7 @@ export default defineConfig({
|
|||||||
terserOptions: {
|
terserOptions: {
|
||||||
format: { ascii_only: true, comments: false },
|
format: { ascii_only: true, comments: false },
|
||||||
},
|
},
|
||||||
chunkSizeWarningLimit: 600,
|
chunkSizeWarningLimit: 800,
|
||||||
},
|
|
||||||
css: {
|
|
||||||
postcss: postcssConfig,
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user