feat(build): umd 构建,支持 <script> 直接引入使用

This commit is contained in:
sight 2022-03-28 17:59:26 +08:00
parent 264866a007
commit e9389d00fe
4 changed files with 47 additions and 1 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ dist/
example/dist/
lib/
es/
umd/
/types/
npm-debug.log*
yarn-debug.log*

View File

@ -6,6 +6,8 @@
"description": "a component library for Vue 3 base on layui-vue",
"homepage": "http://www.layui-vue.com",
"main": "es/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"types": "types/index.d.ts",
"style": "lib/index.css",
"keywords": [
@ -22,9 +24,10 @@
},
"scripts": {
"dev": "vite example",
"build": "npm run build:all && npm run build:es && npm run build:types && npm run build:example",
"build": "npm run build:all && npm run build:es && npm run build:umd && npm run build:types && npm run build:example",
"build:es": "vite build --emptyOutDir --config ./script/build.es.ts",
"build:all": "vite build --emptyOutDir --config ./script/build.all.ts",
"build:umd": "vite build --emptyOutDir --config ./script/build.umd.ts",
"build:types": "rimraf types && tsc -d",
"build:example": "vite build example",
"lint:eslint": "eslint 'src/**/*.{vue,ts,tsx}' --fix",
@ -85,6 +88,7 @@
"files": [
"lib",
"es",
"umd",
"types"
],
"browserslist": [

40
script/build.umd.ts Normal file
View File

@ -0,0 +1,40 @@
import { UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
export default (): UserConfigExport => {
return {
publicDir: false,
resolve: {
alias: [
{
find: '@',
replacement: resolve(process.cwd(), './')
}
]
},
plugins: [
vue(),
],
build: {
cssCodeSplit: false,
outDir: 'umd',
emptyOutDir: true,
lib: {
entry: resolve(process.cwd(), './src/index.ts'),
name: 'LayuiVue',
formats: ['umd'],
fileName: (name) => `index.js`
},
rollupOptions: {
output: {
globals: {
vue: 'Vue'
},
assetFileNames: 'index.css',
},
external: ['vue', 'vue-router']
}
}
}
}

View File

@ -250,6 +250,7 @@ export {
LayNoticeBar,
LayTransition,
LayUpload,
install,
};
export { layer };