chore: Reduce package size by 70%, 1.92 MB to 590 kB (#190)
This commit is contained in:
+1
-2
@@ -41,7 +41,6 @@
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"./client": {
|
||||
"require": "./dist/client.cjs",
|
||||
"import": "./dist/client.js",
|
||||
"types": "./dist/client.d.ts"
|
||||
},
|
||||
@@ -121,7 +120,7 @@
|
||||
"p-map": "^6.0.0",
|
||||
"prettier": "^3.0.1",
|
||||
"simple-git-hooks": "^2.9.0",
|
||||
"tsup": "^7.1.0",
|
||||
"tsup": "^7.2.0",
|
||||
"tsx": "^3.12.7",
|
||||
"typedoc": "^0.25.2",
|
||||
"typedoc-plugin-markdown": "4.0.0-next.23",
|
||||
|
||||
Generated
+4
-71
@@ -139,7 +139,7 @@ importers:
|
||||
specifier: ^2.9.0
|
||||
version: 2.9.0
|
||||
tsup:
|
||||
specifier: ^7.1.0
|
||||
specifier: ^7.2.0
|
||||
version: 7.2.0(typescript@5.2.2)
|
||||
tsx:
|
||||
specifier: ^3.12.7
|
||||
@@ -161,7 +161,7 @@ importers:
|
||||
version: 1.0.0-rc.10(@types/node@20.8.6)
|
||||
vitest:
|
||||
specifier: ^0.34.6
|
||||
version: 0.34.6(happy-dom@12.4.0)
|
||||
version: 0.34.6(happy-dom@12.4.0)(sass@1.64.0)
|
||||
vitest-mock-extended:
|
||||
specifier: ^1.3.1
|
||||
version: 1.3.1(typescript@5.2.2)(vitest@0.34.6)
|
||||
@@ -1092,7 +1092,7 @@ packages:
|
||||
std-env: 3.3.3
|
||||
test-exclude: 6.0.0
|
||||
v8-to-istanbul: 9.1.0
|
||||
vitest: 0.34.6(happy-dom@12.4.0)
|
||||
vitest: 0.34.6(happy-dom@12.4.0)(sass@1.64.0)
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
@@ -4695,73 +4695,7 @@ packages:
|
||||
dependencies:
|
||||
ts-essentials: 9.3.2(typescript@5.2.2)
|
||||
typescript: 5.2.2
|
||||
vitest: 0.34.6(happy-dom@12.4.0)
|
||||
dev: true
|
||||
|
||||
/vitest@0.34.6(happy-dom@12.4.0):
|
||||
resolution: {integrity: sha512-+5CALsOvbNKnS+ZHMXtuUC7nL8/7F1F2DnHGjSsszX8zCjWSSviphCb/NuS9Nzf4Q03KyyDRBAXhF/8lffME4Q==}
|
||||
engines: {node: '>=v14.18.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@edge-runtime/vm': '*'
|
||||
'@vitest/browser': '*'
|
||||
'@vitest/ui': '*'
|
||||
happy-dom: '*'
|
||||
jsdom: '*'
|
||||
playwright: '*'
|
||||
safaridriver: '*'
|
||||
webdriverio: '*'
|
||||
peerDependenciesMeta:
|
||||
'@edge-runtime/vm':
|
||||
optional: true
|
||||
'@vitest/browser':
|
||||
optional: true
|
||||
'@vitest/ui':
|
||||
optional: true
|
||||
happy-dom:
|
||||
optional: true
|
||||
jsdom:
|
||||
optional: true
|
||||
playwright:
|
||||
optional: true
|
||||
safaridriver:
|
||||
optional: true
|
||||
webdriverio:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/chai': 4.3.5
|
||||
'@types/chai-subset': 1.3.3
|
||||
'@types/node': 20.8.6
|
||||
'@vitest/expect': 0.34.6
|
||||
'@vitest/runner': 0.34.6
|
||||
'@vitest/snapshot': 0.34.6
|
||||
'@vitest/spy': 0.34.6
|
||||
'@vitest/utils': 0.34.6
|
||||
acorn: 8.10.0
|
||||
acorn-walk: 8.2.0
|
||||
cac: 6.7.14
|
||||
chai: 4.3.10
|
||||
debug: 4.3.4
|
||||
happy-dom: 12.4.0
|
||||
local-pkg: 0.4.3
|
||||
magic-string: 0.30.2
|
||||
pathe: 1.1.1
|
||||
picocolors: 1.0.0
|
||||
std-env: 3.3.3
|
||||
strip-literal: 1.3.0
|
||||
tinybench: 2.5.0
|
||||
tinypool: 0.7.0
|
||||
vite: 4.4.11(@types/node@20.8.6)(sass@1.64.0)
|
||||
vite-node: 0.34.6(@types/node@20.8.6)(sass@1.64.0)
|
||||
why-is-node-running: 2.2.2
|
||||
transitivePeerDependencies:
|
||||
- less
|
||||
- lightningcss
|
||||
- sass
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
vitest: 0.34.6(happy-dom@12.4.0)(sass@1.64.0)
|
||||
dev: true
|
||||
|
||||
/vitest@0.34.6(happy-dom@12.4.0)(sass@1.64.0):
|
||||
@@ -4828,7 +4762,6 @@ packages:
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
dev: false
|
||||
|
||||
/vscode-oniguruma@1.7.0:
|
||||
resolution: {integrity: sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==}
|
||||
|
||||
+48
-54
@@ -7,22 +7,25 @@ import fs from 'fs-extra';
|
||||
import { consola } from 'consola';
|
||||
import pMap from 'p-map';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
const spinnerText = 'Building WXT';
|
||||
const spinner = ora(spinnerText).start();
|
||||
|
||||
const startTime = Date.now();
|
||||
const outDir = 'dist';
|
||||
const virtualEntrypoints = ['background', 'content-script', 'unlisted-script'];
|
||||
await fs.rm(path.join(outDir, '*'), { recursive: true, force: true });
|
||||
|
||||
await fs.rm(outDir, { recursive: true, force: true });
|
||||
|
||||
const baseConfig: tsup.Options = {
|
||||
format: ['cjs', 'esm'],
|
||||
sourcemap: true,
|
||||
const preset: tsup.Options = {
|
||||
dts: true,
|
||||
silent: true,
|
||||
external: ['vite'],
|
||||
sourcemap: false,
|
||||
external: [
|
||||
'vite',
|
||||
'virtual:user-unlisted-script',
|
||||
'virtual:user-content-script',
|
||||
'virtual:user-background',
|
||||
],
|
||||
};
|
||||
|
||||
function spinnerPMap(configs: tsup.Options[]) {
|
||||
@@ -48,57 +51,48 @@ function spinnerPMap(configs: tsup.Options[]) {
|
||||
}
|
||||
|
||||
const config: tsup.Options[] = [
|
||||
// CJS/ESM
|
||||
{
|
||||
...baseConfig,
|
||||
entry: { index: 'src/index.ts' },
|
||||
...preset,
|
||||
entry: {
|
||||
index: 'src/index.ts',
|
||||
testing: 'src/testing/index.ts',
|
||||
},
|
||||
format: ['cjs', 'esm'],
|
||||
clean: true,
|
||||
},
|
||||
// ESM-only
|
||||
{
|
||||
...preset,
|
||||
entry: {
|
||||
browser: 'src/browser.ts',
|
||||
sandbox: 'src/sandbox/index.ts',
|
||||
client: 'src/client/index.ts',
|
||||
},
|
||||
format: ['esm'],
|
||||
},
|
||||
{
|
||||
...baseConfig,
|
||||
entry: { cli: 'src/cli.ts' },
|
||||
...preset,
|
||||
entry: {
|
||||
'virtual/background-entrypoint': 'src/virtual/background-entrypoint.ts',
|
||||
'virtual/content-script-entrypoint':
|
||||
'src/virtual/content-script-entrypoint.ts',
|
||||
'virtual/mock-browser': 'src/virtual/mock-browser.ts',
|
||||
'virtual/reload-html': 'src/virtual/reload-html.ts',
|
||||
'virtual/unlisted-script-entrypoint':
|
||||
'src/virtual/unlisted-script-entrypoint.ts',
|
||||
},
|
||||
format: ['esm'],
|
||||
splitting: false,
|
||||
dts: false,
|
||||
},
|
||||
// CJS-only
|
||||
{
|
||||
...preset,
|
||||
entry: {
|
||||
cli: 'src/cli.ts',
|
||||
},
|
||||
format: ['cjs'],
|
||||
sourcemap: 'inline',
|
||||
},
|
||||
{
|
||||
...baseConfig,
|
||||
entry: { client: 'src/client/index.ts' },
|
||||
sourcemap: 'inline',
|
||||
},
|
||||
{
|
||||
...baseConfig,
|
||||
entry: { browser: 'src/browser.ts' },
|
||||
format: ['esm'],
|
||||
},
|
||||
{
|
||||
...baseConfig,
|
||||
entry: { sandbox: 'src/sandbox/index.ts' },
|
||||
format: ['esm'],
|
||||
},
|
||||
{
|
||||
...baseConfig,
|
||||
entry: { testing: 'src/testing/index.ts' },
|
||||
},
|
||||
...virtualEntrypoints.map(
|
||||
(entryName): tsup.Options => ({
|
||||
...baseConfig,
|
||||
entry: {
|
||||
[`virtual/${entryName}-entrypoint`]: `src/virtual/${entryName}-entrypoint.ts`,
|
||||
},
|
||||
format: ['esm'],
|
||||
external: [`virtual:user-${entryName}`, 'vite'],
|
||||
}),
|
||||
),
|
||||
{
|
||||
...baseConfig,
|
||||
entry: {
|
||||
'virtual/reload-html': `src/virtual/reload-html.ts`,
|
||||
},
|
||||
format: ['esm'],
|
||||
},
|
||||
{
|
||||
...baseConfig,
|
||||
entry: {
|
||||
'virtual/mock-browser': `src/virtual/mock-browser.ts`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -38,9 +38,13 @@ export async function printFileList(
|
||||
const DEFAULT_COLOR = pc.blue;
|
||||
const CHUNK_COLORS: Record<string, (text: string) => string> = {
|
||||
'.js.map': pc.gray,
|
||||
'.cjs.map': pc.gray,
|
||||
'.mjs.map': pc.gray,
|
||||
'.html': pc.green,
|
||||
'.css': pc.magenta,
|
||||
'.js': pc.cyan,
|
||||
'.cjs': pc.cyan,
|
||||
'.mjs': pc.cyan,
|
||||
'.zip': pc.yellow,
|
||||
};
|
||||
function getChunkColor(filename: string) {
|
||||
|
||||
Reference in New Issue
Block a user