chore: 修改 esm 为 es 包

This commit is contained in:
就眠儀式 2022-04-23 23:44:18 +08:00
parent c9ceb42b46
commit 97e06993b6
3 changed files with 29 additions and 17 deletions

View File

@ -5,7 +5,7 @@
"license": "MIT",
"description": "a component library for Vue 3 base on layui-vue",
"homepage": "http://www.layui-vue.com",
"main": "esm/index.js",
"main": "es/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"types": "types/index.d.ts",
@ -17,14 +17,14 @@
],
"exports": {
".": {
"import": "./esm/index.js"
"import": "./es/index.js"
},
"./lib/": "./lib/",
"./esm/": "./esm/"
"./es/": "./es/"
},
"scripts": {
"build": "npm run build:all && npm run build:esm && npm run build:umd && npm run build:types",
"build:esm": "vite build --emptyOutDir --config ./script/build.esm.ts",
"build": "npm run build:all && npm run build:es && npm run build:umd && npm run build:types",
"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"
@ -59,7 +59,7 @@
},
"files": [
"lib",
"esm",
"es",
"umd",
"types"
],

View File

@ -21,8 +21,16 @@ const inputs = inputsArray.reduce((backObj, pkgName) => {
inputs["index"] = resolve(process.cwd(), "./src/index.ts");
const matchModule: string[] = [
'input', 'dropdown', 'carousel', 'transition', 'datePicker', 'header',
'selectOption', 'skeletonItem', 'tabItem', 'upload'
"input",
"dropdown",
"carousel",
"transition",
"datePicker",
"header",
"selectOption",
"skeletonItem",
"tabItem",
"upload",
];
export default (): UserConfigExport => {
@ -48,7 +56,7 @@ export default (): UserConfigExport => {
build: {
cssCodeSplit: true,
emptyOutDir: true,
outDir: "esm",
outDir: "es",
lib: {
entry: resolve(process.cwd(), "./src/index.ts"),
formats: ["es"],
@ -60,20 +68,24 @@ export default (): UserConfigExport => {
vue: "Vue",
},
manualChunks(id) {
let arr = id.toString().split('/');
if (id.includes('node_modules')) {
let arr = id.toString().split("/");
if (id.includes("node_modules")) {
//id => layui-vue/node_modules/.pnpm/@vue+devtools-api@6.1.4/node_modules/@vue/devtools-api/lib/esm/api/app.js
const chunksName = "_chunks/";
return chunksName + id.toString().split('node_modules/')[2].split('/')[0].toString();
} else if (arr.length >= 2){
return (
chunksName +
id.toString().split("node_modules/")[2].split("/")[0].toString()
);
} else if (arr.length >= 2) {
//if (arr.length >= 2 && arr[arr.length - 1].split('.')[1] != 'ts'){
let entryPoint = arr[arr.length - 2].toString()
let entryPoint = arr[arr.length - 2].toString();
if (matchModule.includes(entryPoint)) {
return entryPoint;
}
}
},
chunkFileNames: ({ name }) => {
console.log(name);
return name === "index" ? "index.js" : "[name]/index.js";
},
entryFileNames: ({ name }) => {

View File

@ -324,7 +324,7 @@ export interface LayuiVueResolverOptions {
const libRE = /^Lay[A-Z]/;
const layerRE = /^(layer|LayLayer)$/;
const iconsRE = /^([A-Z][\w]+Icon|LayIcon)$/;
const esComponentsFolder = "@layui/layui-vue/esm";
const esComponentsFolder = "@layui/layui-vue/es";
function lowerCamelCase(str: string) {
return str.charAt(0).toLowerCase() + str.slice(1);