From 5f3b4395ab1a6c59974e58c2f4433fc73cf16699 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Wed, 21 May 2025 22:12:32 +1000 Subject: [PATCH] fix: rollup compress the utils folder --- package.json | 4 ++-- rollup.config.js | 14 ++++++++++++-- src/main.ts | 21 +++++++++++++++++++++ src/types.d.ts | 29 ----------------------------- src/utils/processTemplateMarcos.ts | 14 ++++++++++++++ tsconfig.json | 2 +- 6 files changed, 50 insertions(+), 34 deletions(-) delete mode 100644 src/types.d.ts diff --git a/package.json b/package.json index eb00821..c6ac4b6 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,12 @@ "name": "laterano", "version": "0.0.1", "main": "dist/main.min.js", - "types": "dist/types.d.ts", + "types": "dist/types/main.d.ts", "module": "dist/main.min.js", "scripts": { "build": "tsc && rollup -c && npm run cleanup-intermediate", "prepare": "npm run build", - "cleanup-intermediate": "rimraf dist/main.js dist/types", + "cleanup-intermediate": "rimraf dist/main.js dist/utils", "quality-check": "biome ci .", "qc": "npm run quality-check", "lint": "biome format . --write" diff --git a/rollup.config.js b/rollup.config.js index 0b4fb83..d2d2e5a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,7 +5,7 @@ import dts from 'rollup-plugin-dts' export default [ { - input: 'dist/main.js', + input: 'src/main.ts', output: [ { file: 'dist/main.min.js', @@ -15,10 +15,20 @@ export default [ ], plugins: [resolve(), typescript()], }, + { + input: 'dist/utils/index.js', + output: { + file: 'dist/utils.bundle.min.js', + format: 'esm', + inlineDynamicImports: true, + plugins: [terser()], + }, + plugins: [resolve(), typescript({ outDir: 'dist' })], + }, { input: 'dist/types/main.d.ts', output: { - file: 'dist/types.d.ts', + file: 'dist/types/main.d.ts', format: 'es', }, plugins: [dts()], diff --git a/src/main.ts b/src/main.ts index c184235..e1c7693 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,26 @@ import utils from './utils/index' +interface ComponentOptions { + tag: string + template: string + style?: string + onMount?: (this: CustomElement) => void + onUnmount?: () => void + onAttributeChanged?: ( + attrName: string, + oldValue: string, + newValue: string, + ) => void + states?: Record + statesListeners?: { [key: string]: (value: unknown) => void } + funcs?: { [key: string]: (...args: unknown[]) => void } +} + +interface CustomElement extends HTMLElement { + setState(key_path: string, value: unknown): void + getState(key_path: string): unknown +} + export default (options: ComponentOptions) => { const { tag, diff --git a/src/types.d.ts b/src/types.d.ts deleted file mode 100644 index 14904f7..0000000 --- a/src/types.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -interface CustomElement extends HTMLElement { - setState(key_path: string, value: unknown): void - getState(key_path: string): unknown -} - -interface ListRenderingContext { - states: Record - stateToElementsMap: Record> - statesListeners: Record void> - setState: (keyPath: string, value: unknown) => void - getState: (keyPath: string) => unknown - triggerFunc: (eventName: string, ...args: unknown[]) => void -} - -interface ComponentOptions { - tag: string - template: string - style?: string - onMount?: (this: CustomElement) => void - onUnmount?: () => void - onAttributeChanged?: ( - attrName: string, - oldValue: string, - newValue: string, - ) => void - states?: Record - statesListeners?: { [key: string]: (value: unknown) => void } - funcs?: { [key: string]: (...args: unknown[]) => void } -} diff --git a/src/utils/processTemplateMarcos.ts b/src/utils/processTemplateMarcos.ts index fa250c9..653cd9d 100644 --- a/src/utils/processTemplateMarcos.ts +++ b/src/utils/processTemplateMarcos.ts @@ -1,5 +1,19 @@ import setupArrowFunctionHandler from './setupArrowFunctionHandler' +interface CustomElement extends HTMLElement { + setState(key_path: string, value: unknown): void + getState(key_path: string): unknown +} + +interface ListRenderingContext { + states: Record + stateToElementsMap: Record> + statesListeners: Record void> + setState: (keyPath: string, value: unknown) => void + getState: (keyPath: string) => unknown + triggerFunc: (eventName: string, ...args: unknown[]) => void +} + export default function processTemplateMacros( element: Element, context: CustomElement, diff --git a/tsconfig.json b/tsconfig.json index eb72527..37a0107 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,7 +35,7 @@ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": ["./src/types"], /* Specify multiple folders that act like './node_modules/@types'. */ + "typeRoots": ["./src/types"], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */