!28 迁移 build.* 构建脚本到 script 目录下

Merge pull request !28 from Sight/develop
This commit is contained in:
就眠儀式 2022-02-17 05:39:03 +00:00 committed by Gitee
commit cf741e66c3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 42 additions and 36 deletions

View File

@ -1,26 +0,0 @@
var fs = require('fs');
var { resolve } = require('path');
const inputDir = resolve(__dirname, './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);
}
});
})

View File

@ -23,9 +23,9 @@
"scripts": {
"dev": "vite example",
"build": "npm run build:all && npm run build:es && npm run build:less && npm run build:types && npm run build:example",
"build:es": "vite build --emptyOutDir --config ./build.es.ts",
"build:all": "vite build --emptyOutDir --config ./build.all.ts",
"build:less": "node build.less.ts",
"build:es": "vite build --emptyOutDir --config ./script/build.es.ts",
"build:all": "vite build --emptyOutDir --config ./script/build.all.ts",
"build:less": "node ./script/build.less.ts",
"build:types": "rimraf types && tsc -d",
"build:example": "vite build example",
"lint:eslint": "eslint 'src/**/*.{vue,ts,tsx}' --fix",

View File

View File

@ -9,7 +9,7 @@ export default (): UserConfigExport => {
alias: [
{
find: '@',
replacement: resolve(__dirname, './')
replacement: resolve(process.cwd(), './')
}
]
},
@ -21,7 +21,7 @@ export default (): UserConfigExport => {
outDir: 'lib',
emptyOutDir: true,
lib: {
entry: resolve(__dirname, './src/index.ts'),
entry: resolve(process.cwd(), './src/index.ts'),
name: 'layui-vue',
formats: ['es'],
fileName: (name) => `index.js`

View File

@ -3,7 +3,7 @@ import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import * as fs from 'fs'
const inputDir = resolve(__dirname, './src/component')
const inputDir = resolve(process.cwd(), './src/component')
const inputsArray = fs.readdirSync(inputDir).filter((name) => {
const componentDir = resolve(inputDir, name)
@ -12,11 +12,11 @@ const inputsArray = fs.readdirSync(inputDir).filter((name) => {
})
const inputs = inputsArray.reduce((backObj, pkgName) => {
backObj[pkgName] = resolve(__dirname, `./src/component/${pkgName}/index.ts`)
backObj[pkgName] = resolve(process.cwd(), `./src/component/${pkgName}/index.ts`)
return backObj
}, {})
inputs['index'] = resolve(__dirname, './src/index.ts')
inputs['index'] = resolve(process.cwd(), './src/index.ts')
export default (): UserConfigExport => {
return {
@ -25,7 +25,7 @@ export default (): UserConfigExport => {
alias: [
{
find: '@',
replacement: resolve(__dirname, './')
replacement: resolve(process.cwd(), './')
}
]
},

32
script/build.less.ts Normal file
View 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);
}
});
})