ソースを参照

fix: tsc error file

richard1015 4 年 前
コミット
01ac2d64be

+ 13 - 6
package.json

@@ -5,10 +5,16 @@
     "tag": "next"
   },
   "description": "一套京东风格的轻量级移动端 Vue 组件库",
-  "main": "dist/lib/nutui.js",
-  "module": "dist/es/nutui.js",
-  "style": "dist/lib/index.css",
-  "typings": "dist/types/index.d.ts",
+  "main": "dist/nutui.umd.js",
+  "module": "dist/nutui.es.js",
+  "exports": {
+    ".": {
+      "import": "./dist/nutui.es.js",
+      "require": "./dist/nutui.umd.js"
+    }
+  },
+  "style": "dist/style.css",
+  "typings": "dist/types/nutui.d.ts",
   "keywords": [
     "nutui",
     "nutui2",
@@ -36,11 +42,12 @@
     "CHANGELOG.md"
   ],
   "scripts": {
-    "dev": "vite --open",
+    "dev": "tsc && vite --open",
     "build:site": "vite build",
     "build": "vite build -c vite.config.build.ts",
+    "build:ts": "rm -rf dist/es && tsc",
     "serve": "vite preview",
-    "upload": "vite build && node ./jd/upload.js",
+    "upload": "yarn build:site && node ./jd/upload.js",
     "add": "node jd/createComponentMode.js"
   },
   "dependencies": {

+ 3 - 3
src/packages/dialog/index.ts

@@ -3,8 +3,8 @@ import { defineComponent, createVNode, render, toRef, watch } from 'vue';
 
 const confirmConstructor = defineComponent(dialog);
 
-let instance;
-const Dialog = options => {
+let instance: any;
+const Dialog = (options: any) => {
   options = options ? options : {};
 
   options.id = options.id || 'nut-dialog-default-id';
@@ -38,7 +38,7 @@ Dialog.close = function() {
   }
 };
 
-Dialog.install = function(app) {
+Dialog.install = function(app: any) {
   app.use(dialog);
   app.config.globalProperties.$dialog = Dialog;
 };

+ 8 - 8
src/packages/notify/notify.ts

@@ -38,7 +38,7 @@ const clearNotify = (id?: string) => {
   }
 };
 
-const updateNotify = opts => {
+const updateNotify = (opts: any) => {
   const container = document.getElementById(opts.id);
   if (container) {
     const currentOpt = optsMap.find(item => item.id === opts.id);
@@ -53,7 +53,7 @@ const updateNotify = opts => {
   }
 };
 
-const mountNotify = opts => {
+const mountNotify = (opts: any) => {
   opts.unmount = clearNotify;
   let _id;
   if (opts.id) {
@@ -81,7 +81,7 @@ const mountNotify = opts => {
   return instance.component.ctx;
 };
 
-const errorMsg = msg => {
+const errorMsg = (msg: string) => {
   if (!msg) {
     console.warn('[NutUI Notify]: msg不能为空');
     return;
@@ -89,23 +89,23 @@ const errorMsg = msg => {
 };
 
 export const Notify = {
-  text(msg, obj = {}) {
+  text(msg: string, obj = {}) {
     errorMsg(msg);
     return mountNotify({ ...obj, msg });
   },
-  primary(msg, obj = {}) {
+  primary(msg: string, obj = {}) {
     errorMsg(msg);
     return mountNotify({ ...obj, msg, type: 'primary' });
   },
-  success(msg, obj = {}) {
+  success(msg: string, obj = {}) {
     errorMsg(msg);
     return mountNotify({ ...obj, msg, type: 'success' });
   },
-  danger(msg, obj = {}) {
+  danger(msg: string, obj = {}) {
     errorMsg(msg);
     return mountNotify({ ...obj, msg, type: 'danger' });
   },
-  warn(msg, obj = {}) {
+  warn(msg: string, obj = {}) {
     errorMsg(msg);
     return mountNotify({ ...obj, msg, type: 'warning' });
   },

ファイルの差分が大きいため隠しています
+ 8 - 8
src/packages/toast/index.ts


+ 1 - 1
src/sites/service/ArticleApiService.ts

@@ -17,7 +17,7 @@ export class ArticleApiService {
    * 保存用户访问数据
    * @returns
    */
-  saveUserInfo(parmas) {
+  saveUserInfo(parmas: any) {
     return this.httpClient.request('/visit/saveVisitInfo', 'post', parmas);
   }
 }

+ 1 - 1
src/sites/service/HttpClient.ts

@@ -62,7 +62,7 @@ export class HttpClient {
  * @param {any} value 接口响应数据
  * @param {string} message 服务器响应信息msg
  */
-interface ResponseData {
+export interface ResponseData {
   state: number;
   value?: any;
   message: string;

+ 2 - 2
src/utils/date.ts

@@ -47,7 +47,7 @@ const Utils = {
     if (/^0/.test(month)) {
       month = month.split('')[1];
     }
-    return [
+    return ([
       0,
       31,
       this.isLeapYear(Number(year)) ? 29 : 28,
@@ -61,7 +61,7 @@ const Utils = {
       31,
       30,
       31
-    ][month];
+    ] as number[])[month as any];
   },
 
   /**

+ 1 - 1
src/utils/raf.ts

@@ -8,7 +8,7 @@ function requestAniFrame() {
       }
     );
   } else {
-    return function(callback) {
+    return function(callback: Function) {
       setTimeout(callback, 1000 / 60);
     };
   }

+ 5 - 2
tsconfig.json

@@ -7,15 +7,18 @@
     "moduleResolution": "node",
     "strict": true,
     "jsx": "preserve",
-    "sourceMap": true,
+    "sourceMap": false,
+    "declaration": true,
+    "removeComments":true,
     "resolveJsonModule": true,
     "esModuleInterop": true,
     "lib": ["esnext", "dom"],
+    "outDir": "./dist/es",
     "types": ["vite/client"],
     "paths": {
       "@/*": ["src/*"]
     }
   },
   "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
-  "exclude": ["./node_modules"]
+  "exclude": ["./node_modules","src/sites"]
 }

+ 8 - 10
vite.config.build.ts

@@ -24,16 +24,14 @@ export default defineConfig({
   ],
   build: {
     rollupOptions: {
-      // make sure to externalize deps that shouldn't be bundled
-      // into your library
-      // external: ['vue'],
-      // output: {
-      //   // Provide global variables to use in the UMD build
-      //   // for externalized deps
-      //   globals: {
-      //     vue: 'Vue'
-      //   }
-      // }
+      // 请确保外部化那些你的库中不需要的依赖
+      external: ['vue'],
+      output: {
+        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
+        globals: {
+          vue: 'Vue'
+        }
+      }
     },
     lib: {
       entry: 'src/nutui.ts',