diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a50c511..b67bcf5f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,5 @@ { - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact" - ], + "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], "editor.formatOnSave": true, "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" @@ -22,9 +17,9 @@ "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[markdown]": { - "editor.formatOnSave": false, + "editor.formatOnSave": false }, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index d1e3fc49..b0652950 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "build:tsc": "concurrently \"npm:build:tsc-*\"", "build:tsc-es": "tsc --emitDeclarationOnly -d --outDir es/", "build:tsc-esm": "tsc --emitDeclarationOnly -d --outDir esm/", - "build:tsc-lib": "tsc --emitDeclarationOnly -d --outDir lib/" + "build:tsc-lib": "tsc --emitDeclarationOnly -d --outDir lib/", + "build:tsc-cjs": "tsc --emitDeclarationOnly -d --outDir cjs/" }, "publishConfig": { "registry": "https://registry.npmjs.org/" diff --git a/script/rollup.config.js b/script/rollup.config.js index 632b3008..5fa35c74 100644 --- a/script/rollup.config.js +++ b/script/rollup.config.js @@ -173,14 +173,28 @@ const esmConfig = { }, }; -/** @type {import('rollup').RollupOptions} */ +// 按需加载组件 不带 css 样式 const libConfig = { + input: inputList.concat('!src/index-lib.ts'), + external: externalDeps.concat(externalPeerDeps), + plugins: [multiInput()].concat(getPlugins({ extractMultiCss: true })), + output: { + banner, + dir: 'lib/', + format: 'esm', + sourcemap: true, + chunkFileNames: '_chunks/dep-[hash].js', + }, +}; + +// commonjs 导出规范,不带 css 样式 +const cjsConfig = { input: inputList, external: externalDeps.concat(externalPeerDeps), plugins: [multiInput()].concat(getPlugins()), output: { banner, - dir: 'lib/', + dir: 'cjs/', format: 'cjs', sourcemap: true, exports: 'named', @@ -227,4 +241,13 @@ const umdMinConfig = { }, }; -export default [cssConfig, libConfig, esConfig, esmConfig, umdConfig, umdMinConfig]; +// 单独导出 reset.css 到 dist 目录,兼容旧版本样式 +const resetCss = { + input: 'src/_common/style/mobile/_reset.less', + output: { + file: 'dist/reset.css', + }, + plugins: [postcss({ extract: true })], +}; + +export default [cssConfig, esConfig, esmConfig, libConfig, cjsConfig, umdConfig, umdMinConfig, resetCss]; diff --git a/tsconfig.json b/tsconfig.json index 900c2497..15b8a014 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,10 +8,7 @@ "outDir": "lib", "declaration": true, "sourceMap": true, - "lib": [ - "esnext", - "dom" - ], + "lib": ["esnext", "dom"], "importHelpers": true, "allowSyntheticDefaultImports": true, "suppressImplicitAnyIndexErrors": true, @@ -20,17 +17,14 @@ "tdesign-mobile-react": ["src"], "tdesign-mobile-react/*": ["src/*"], "@test/utils": ["test/utils"], - "@common/*": ["src/_common/*"], + "@common/*": ["src/_common/*"] }, "allowJs": true, "checkJs": true, "downlevelIteration": true, "esModuleInterop": true }, - "include": [ - "./src", - "./global.d.ts" - ], + "include": ["./src", "./global.d.ts"], "exclude": [ "**/**/__tests__/*", "**/**/_example/*", @@ -38,8 +32,9 @@ "src/_common", "dist", "lib", + "cjs", "esm", "es" ], "compileOnSave": false -} \ No newline at end of file +}