diff --git a/__unconfig_vite.config.ts b/__unconfig_vite.config.ts new file mode 100644 index 0000000..45a2036 --- /dev/null +++ b/__unconfig_vite.config.ts @@ -0,0 +1,42 @@ +let __unconfig_data +const __unconfig_stub = function (data) { + __unconfig_data = data +} +__unconfig_stub.default = (data) => { + __unconfig_data = data +} +import * as path from 'path' +import dts from 'vite-plugin-dts' +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' +import libCss from 'vite-plugin-libcss' +import vueJsx from '@vitejs/plugin-vue-jsx' +import { terser } from 'rollup-plugin-terser' + +// https://vitejs.dev/config/ +const __unconfig_default = defineConfig({ + base: './', + plugins: [vue(), vueJsx(), dts(), libCss()], + build: { + lib: { + entry: path.resolve(__dirname, 'src/index.ts'), + name: 'SimpleWorkerTimer', + fileName: (format) => `index.${format}.js` + }, + // https://rollupjs.org/guide/en/#big-list-of-options + rollupOptions: { + treeshake: true, + external: ['vue'], + output: { + globals: { + vue: 'vue' + }, + exports: 'named' + }, + plugins: [terser({ compress: { drop_console: true } })] + } + } +}) + +if (typeof __unconfig_default === 'function') __unconfig_default(...[{ command: 'serve', mode: 'development' }]) +export default __unconfig_data diff --git a/example/Vue3/.gitignore b/example/Vue3/.gitignore index a547bf3..7a9d1bc 100644 --- a/example/Vue3/.gitignore +++ b/example/Vue3/.gitignore @@ -22,3 +22,5 @@ dist-ssr *.njsproj *.sln *.sw? + +.vercel diff --git a/package.json b/package.json index 72cb950..f392162 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "main": "dist/index.umd.js", "module": "dist/index.es.js", + "types": "dist/index.d.ts", "unpkg": "dist/index.umd.js", "jsdelivr": "dist/index.umd.js", "exports": { diff --git a/src/utils/index.ts b/src/utils/index.ts index 47849d2..a38a21f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,16 +1,16 @@ import { IDate } from '../types/index' -// 正则格式化日期 +/** 正则格式化日期 */ export const formatDate = (date: Date, dateFormat: string) => { /* 单独格式化年份,根据y的字符数量输出年份 - * 例如:yyyy => 2019 - yy => 19 - y => 9 - */ + * 例如:yyyy => 2019 + yy => 19 + y => 9 + */ if (/(y+)/.test(dateFormat)) { dateFormat = dateFormat.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) } - // 格式化月、日、时、分、秒 + /** 格式化月、日、时、分、秒 */ const o: IDate = { 'm+': date.getMonth() + 1, 'd+': date.getDate(), @@ -20,7 +20,7 @@ export const formatDate = (date: Date, dateFormat: string) => { } for (const k in o) { if (new RegExp(`(${k})`).test(dateFormat)) { - // 取出对应的值 + /** 取出对应的值 */ const str = o[k] + '' /* 根据设置的格式,输出对应的字符 * 例如: 早上8时,hh => 08,h => 8 @@ -33,7 +33,7 @@ export const formatDate = (date: Date, dateFormat: string) => { return dateFormat } -// 日期时间补零 +/** 日期时间补零 */ export const padLeftZero = (str: string | any[]) => { return ('00' + str).substr(str.length) } diff --git a/src/worker.ts b/src/worker.ts index e113da7..f6e65c4 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,4 +1,6 @@ -// 正则格式化日期 +/** 为什么不用utils导入的原因: https://github.com/vitejs/vite/issues/9882 */ + +/** 正则格式化日期 */ const formatDate = (date: Date, dateFormat: string) => { /* 单独格式化年份,根据y的字符数量输出年份 * 例如:yyyy => 2019 @@ -33,7 +35,7 @@ const formatDate = (date: Date, dateFormat: string) => { return dateFormat } -// 日期时间补零 +/** 日期时间补零 */ const padLeftZero = (str: string | any[]) => { return ('00' + str).substr(str.length) }