Skip to content

Commit 72a4346

Browse files
BeiyanYunyiLhcfl
authored andcommitted
perf: ⚡ switch to swc, no explicit import h
1 parent 615bb0a commit 72a4346

8 files changed

+205
-371
lines changed

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@
1010
"build": "rollup -c ./rollup.config.mjs"
1111
},
1212
"dependencies": {
13-
"@rollup/plugin-commonjs": "^26.0.1",
1413
"@rollup/plugin-node-resolve": "^15.2.3",
15-
"@rollup/plugin-terser": "^0.4.4",
16-
"@rollup/plugin-typescript": "^11.1.6",
1714
"hexo-renderer-pug": "^0.0.5",
1815
"hexo-renderer-stylus": "^0.2.3",
1916
"rollup": "^4.21.2",
2017
"typescript": "^5.5.4"
2118
},
2219
"devDependencies": {
2320
"@prettier/plugin-pug": "^3.0.0",
21+
"@swc/core": "^1.7.23",
2422
"eslint": "^9.4.0",
2523
"fuse.js": "^7.0.0",
2624
"prettier": "^3.3.1",
2725
"stylus-supremacy": "^2.17.5",
28-
"tslib": "^2.7.0"
26+
"unplugin-swc": "^1.5.1"
2927
},
3028
"packageManager": "[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
3129
}

pnpm-lock.yaml

+183-353
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.mjs

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import resolve from '@rollup/plugin-node-resolve';
2-
import commonjs from '@rollup/plugin-commonjs';
3-
import typescript from "@rollup/plugin-typescript";
4-
import terser from '@rollup/plugin-terser';
2+
import { resolve as pathResolve } from 'node:path';
3+
import { defineConfig } from 'rollup';
4+
import swc from 'unplugin-swc';
55

6-
export default [
6+
export default defineConfig([
77
// browser-friendly UMD build
88
{
99
input: 'src/main.ts',
1010
output: {
1111
name: 'main.js',
12-
file: "source/js_complied/bundle.js",
12+
file: 'source/js_complied/bundle.js',
1313
// format: 'umd',
1414
format: 'umd',
1515
},
1616
plugins: [
1717
resolve(), // so Rollup can find `ms`
18-
commonjs(), // so Rollup can convert `ms` to an ES module
19-
typescript(),
20-
terser(),
18+
swc.rollup({
19+
minify: true,
20+
jsc: {
21+
target: 'esnext',
22+
baseUrl: pathResolve('./'),
23+
paths: {
24+
'@/*': ['./src/*'],
25+
},
26+
},
27+
}),
2128
],
2229
},
2330

@@ -35,4 +42,4 @@ export default [
3542
// { file: pkg.module, format: 'es' },
3643
// ],
3744
// },
38-
];
45+
]);

src/components/search.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Fuse, { type FuseResult } from 'fuse.js';
22
import { AnatoloDynamicResource } from '@/anatolo/dynamic-resource';
33
import { AnatoloRef } from '@/anatolo/ref';
4-
import { escapeHTML, h, nextTick } from '@/utils/main';
4+
import { escapeHTML, nextTick } from '@/utils/main';
55
import { Component } from './base';
66
import { router } from '@/anatolo/router';
77
import { SearchResourceCollection, SearchResource, SearchResourcePage } from '@/types/search';

src/utils/friend-link.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { escapeHTML } from './escape-html';
2-
import { h } from './html-helper';
32

43
export function make_friends_list() {
54
try {
File renamed without changes.

src/utils/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { h } from './html-helper';
1+
export { h } from './jsx-runtime';
22

33
export function nextTick(fn: () => void) {
44
setTimeout(() => {

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
/* Language and Environment */
1414
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16-
"jsx": "react", /* Specify what JSX code is generated. */
16+
"jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1818
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1919
"jsxFactory": "h", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
2020
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
21+
"jsxImportSource": "@/utils", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
2222
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
2323
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2424
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

0 commit comments

Comments
 (0)