From 61abde290efc7dc2166fcb3fa63ea2ce008b40ba Mon Sep 17 00:00:00 2001 From: zhoulixiang <18366276315@163.com> Date: Tue, 14 Nov 2023 17:22:22 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E6=89=93=E5=8C=85=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E8=BF=81=E7=A7=BB=E8=87=B3=20vite"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 14 ++++++++++---- rollup.config.js | 37 +++++++++++++++++++++++++++++++++++++ rollup.esm.config.js | 33 +++++++++++++++++++++++++++++++++ tsconfig.json | 5 +---- vite.config.ts | 22 ---------------------- 5 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 rollup.config.js create mode 100644 rollup.esm.config.js delete mode 100644 vite.config.ts diff --git a/package.json b/package.json index deb35e9..628ce3a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "typings": "./types/index.d.ts", "scripts": { "test": "mocha", - "build": "tsc && vite build", + "build": "rollup -c && rollup -c rollup.esm.config.js", "commit": "git-cz", "coverage": "istanbul cover _mocha -- -R spec --timeout 15000 --recursive", "coverage:check": "istanbul check-coverage", @@ -54,6 +54,9 @@ "devDependencies": { "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", + "@rollup/plugin-commonjs": "^17.1.0", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^11.2.0", "@types/jest": "^26.0.20", "@typescript-eslint/eslint-plugin": "^4.26.0", "@typescript-eslint/parser": "^4.26.0", @@ -64,9 +67,12 @@ "eslint": "^7.22.0", "istanbul": "^0.4.5", "mocha": "^8.3.2", - "tslib": "^2.6.2", - "typescript": "^4.2.3", - "vite": "^4.4.11" + "rollup": "2.60.0", + "rollup-plugin-alias": "^2.2.0", + "rollup-plugin-cleanup": "^3.2.1", + "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.34.1", + "typescript": "^4.2.3" }, "config": { "commitizen": { diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..1ef5bd4 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,37 @@ +import path from 'path'; +import json from '@rollup/plugin-json'; +import { terser } from 'rollup-plugin-terser'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; // commonjs模块转换插件 +import cleanup from 'rollup-plugin-cleanup'; +import ts from 'rollup-plugin-typescript2'; +import alias from 'rollup-plugin-alias'; + +const plugins = [ + cleanup(), + json(), + nodeResolve(), + ts({ + tsconfig: path.resolve(__dirname, './tsconfig.json'), // 导入本地ts配置 + clean: true, + useTsconfigDeclarationDir: true, + }), + commonjs(), + alias({ + entries: [{ find: '@', replacement: './lib' }], + }), + terser(), +]; + +module.exports = { + input: path.resolve('./lib/index.ts'), + output: [ + { + exports: 'auto', + file: path.resolve(__dirname, './dist/index.js'), + format: 'umd', + name: 'pinyinPro', + }, + ], + plugins, +}; diff --git a/rollup.esm.config.js b/rollup.esm.config.js new file mode 100644 index 0000000..a9152b9 --- /dev/null +++ b/rollup.esm.config.js @@ -0,0 +1,33 @@ +import path from 'path'; +import json from '@rollup/plugin-json'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; // commonjs模块转换插件 +import ts from 'rollup-plugin-typescript2'; +import alias from 'rollup-plugin-alias'; + +const plugins = [ + json(), + nodeResolve(), + ts({ + tsconfig: path.resolve(__dirname, './tsconfig.json'), // 导入本地ts配置 + clean: true, + useTsconfigDeclarationDir: true, + }), + commonjs(), + alias({ + entries: [{ find: '@', replacement: './lib' }], + }), +]; + +module.exports = { + input: path.resolve('./lib/index.ts'), + output: [ + { + exports: 'auto', + file: path.resolve(__dirname, './dist/index.mjs'), + format: 'es', + sourcemap: false, + }, + ], + plugins, +}; diff --git a/tsconfig.json b/tsconfig.json index ce9197b..d7da20b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES5", + "target": "es6", "module": "esnext", "strict": true, "jsx": "preserve", @@ -10,16 +10,13 @@ "esModuleInterop": true, "allowSyntheticDefaultImports": true, "isolatedModules": false, - "downlevelIteration": true, "sourceMap": false, "declaration": true, "declarationDir": "types", - "emitDeclarationOnly": true, "baseUrl": "./", "paths": { "@/*": ["lib/*"] } }, - "include": ["lib/**/*.ts"], "exclude": ["node_modules", "types"] } diff --git a/vite.config.ts b/vite.config.ts deleted file mode 100644 index 5724ac1..0000000 --- a/vite.config.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { defineConfig } from 'vite'; -import path from 'path'; - -// https://vitejs.dev/config/ -export default defineConfig({ - build: { - lib: { - entry: ['lib/index.ts'], - formats: ['es', 'cjs'], - fileName: 'index', - name: 'pinyinPro', - }, - - minify: true, - emptyOutDir: true, - }, - resolve: { - alias: { - '@': path.resolve(__dirname, './lib'), - }, - }, -});