chore(build): 迁移 build.* 构建脚本到 script 目录下
This commit is contained in:
40
script/build.all.ts
Normal file
40
script/build.all.ts
Normal 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: 'lib',
|
||||
emptyOutDir: true,
|
||||
lib: {
|
||||
entry: resolve(process.cwd(), './src/index.ts'),
|
||||
name: 'layui-vue',
|
||||
formats: ['es'],
|
||||
fileName: (name) => `index.js`
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
globals: {
|
||||
vue: 'Vue'
|
||||
},
|
||||
assetFileNames: 'index.css',
|
||||
},
|
||||
external: ['vue', 'vue-router']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
script/build.es.ts
Normal file
64
script/build.es.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
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']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
script/build.less.ts
Normal file
32
script/build.less.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* merge less file
|
||||
* <p>
|
||||
*/
|
||||
var fs = require('fs');
|
||||
var { resolve } = require('path');
|
||||
|
||||
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')
|
||||
})
|
||||
|
||||
// 读取基础变量 与 公共样式
|
||||
var content = fs.readFileSync("./src/theme/variable.less").toString() + '\n\n';
|
||||
content += fs.readFileSync("./src/theme/index.less").toString() + '\n\n';
|
||||
|
||||
// 组件样式
|
||||
inputsArray.forEach(function (f) {
|
||||
var path = "./src/component/" + f + "/index.less";
|
||||
fs.exists(path, function (exists) {
|
||||
if (exists) {
|
||||
var c = fs.readFileSync(path);
|
||||
content += c.toString() + '\n\n';
|
||||
// @ts-ignore
|
||||
content = content.replaceAll(/\@import.*?\;/g, "");
|
||||
fs.writeFileSync('./lib/index.less', content);
|
||||
}
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user