chore: 修改 es 为 esm 包

This commit is contained in:
就眠儀式 2022-04-23 22:42:47 +08:00
parent 09ea8472ab
commit c9ceb42b46
4 changed files with 5 additions and 75 deletions

View File

@ -20,11 +20,10 @@
"import": "./esm/index.js"
},
"./lib/": "./lib/",
"./es/": "./es/"
"./esm/": "./esm/"
},
"scripts": {
"build": "npm run build:all && npm run build:es && npm run build:esm && npm run build:umd && npm run build:types",
"build:es": "vite build --emptyOutDir --config ./script/build.es.ts",
"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:all": "vite build --emptyOutDir --config ./script/build.all.ts",
"build:umd": "vite build --emptyOutDir --config ./script/build.umd.ts",
@ -60,7 +59,7 @@
},
"files": [
"lib",
"es",
"esm",
"umd",
"types"
],

View File

@ -1,67 +0,0 @@
import { UserConfigExport } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import * as fs from "fs";
const inputDir = resolve(process.cwd(), "./src/component");
const inputsArray = fs.readdirSync(inputDir).filter((name) => {
const componentDir = resolve(inputDir, name);
const isDir = fs.lstatSync(componentDir).isDirectory();
return isDir && fs.readdirSync(componentDir).includes("index.ts");
});
const inputs = inputsArray.reduce((backObj, pkgName) => {
backObj[pkgName] = resolve(
process.cwd(),
`./src/component/${pkgName}/index.ts`
);
return backObj;
}, {});
inputs["index"] = resolve(process.cwd(), "./src/index.ts");
export default (): UserConfigExport => {
return {
publicDir: false,
resolve: {
alias: [
{
find: "@",
replacement: resolve(process.cwd(), "./"),
},
],
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
postcss: {},
},
plugins: [vue()],
build: {
cssCodeSplit: true,
emptyOutDir: true,
outDir: "es",
lib: {
entry: "./index.ts",
formats: ["es"],
},
rollupOptions: {
input: inputs,
output: {
globals: {
vue: "Vue",
},
entryFileNames: ({ name }) => {
return name === "index" ? "index.js" : "[name]/index.js";
},
assetFileNames: "[name]/index.css",
},
external: ["vue", "vue-router"],
},
},
};
};

View File

@ -59,9 +59,7 @@ export default (): UserConfigExport => {
globals: {
vue: "Vue",
},
manualChunks(id) {
console.log("mmmmm",id);
manualChunks(id) {
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

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/es";
const esComponentsFolder = "@layui/layui-vue/esm";
function lowerCamelCase(str: string) {
return str.charAt(0).toLowerCase() + str.slice(1);