Skip to content

Commit

Permalink
perf: ⚡ switch to swc, no explicit import h
Browse files Browse the repository at this point in the history
  • Loading branch information
BeiyanYunyi authored and Lhcfl committed Sep 6, 2024
1 parent 615bb0a commit 72a4346
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 371 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@
"build": "rollup -c ./rollup.config.mjs"
},
"dependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"hexo-renderer-pug": "^0.0.5",
"hexo-renderer-stylus": "^0.2.3",
"rollup": "^4.21.2",
"typescript": "^5.5.4"
},
"devDependencies": {
"@prettier/plugin-pug": "^3.0.0",
"@swc/core": "^1.7.23",
"eslint": "^9.4.0",
"fuse.js": "^7.0.0",
"prettier": "^3.3.1",
"stylus-supremacy": "^2.17.5",
"tslib": "^2.7.0"
"unplugin-swc": "^1.5.1"
},
"packageManager": "[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
}
536 changes: 183 additions & 353 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from "@rollup/plugin-typescript";
import terser from '@rollup/plugin-terser';
import { resolve as pathResolve } from 'node:path';
import { defineConfig } from 'rollup';
import swc from 'unplugin-swc';

export default [
export default defineConfig([
// browser-friendly UMD build
{
input: 'src/main.ts',
output: {
name: 'main.js',
file: "source/js_complied/bundle.js",
file: 'source/js_complied/bundle.js',
// format: 'umd',
format: 'umd',
},
plugins: [
resolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
typescript(),
terser(),
swc.rollup({
minify: true,
jsc: {
target: 'esnext',
baseUrl: pathResolve('./'),
paths: {
'@/*': ['./src/*'],
},
},
}),
],
},

Expand All @@ -35,4 +42,4 @@ export default [
// { file: pkg.module, format: 'es' },
// ],
// },
];
]);
2 changes: 1 addition & 1 deletion src/components/search.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Fuse, { type FuseResult } from 'fuse.js';
import { AnatoloDynamicResource } from '@/anatolo/dynamic-resource';
import { AnatoloRef } from '@/anatolo/ref';
import { escapeHTML, h, nextTick } from '@/utils/main';
import { escapeHTML, nextTick } from '@/utils/main';
import { Component } from './base';
import { router } from '@/anatolo/router';
import { SearchResourceCollection, SearchResource, SearchResourcePage } from '@/types/search';
Expand Down
1 change: 0 additions & 1 deletion src/utils/friend-link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { escapeHTML } from './escape-html';
import { h } from './html-helper';

export function make_friends_list() {
try {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { h } from './html-helper';
export { h } from './jsx-runtime';

export function nextTick(fn: () => void) {
setTimeout(() => {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
/* Language and Environment */
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"jsx": "react", /* Specify what JSX code is generated. */
"jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
"jsxFactory": "h", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
"jsxImportSource": "@/utils", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
Expand Down

0 comments on commit 72a4346

Please sign in to comment.