2021-08-03 09:12:34 +08:00
|
|
|
import chalk from 'chalk'
|
|
|
|
import gulp from 'gulp'
|
|
|
|
import gulpSass from 'gulp-sass'
|
|
|
|
import dartSass from 'sass'
|
|
|
|
import autoprefixer from 'gulp-autoprefixer'
|
|
|
|
import cleanCSS from 'gulp-clean-css'
|
|
|
|
import rename from 'gulp-rename'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { buildOutput } from '../../build/paths'
|
2021-08-03 09:12:34 +08:00
|
|
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
const noElPrefixFile = /(index|base|display)/
|
|
|
|
|
|
|
|
const sass = gulpSass(dartSass)
|
|
|
|
export const distFolder = './lib'
|
|
|
|
|
2021-08-04 11:25:22 +08:00
|
|
|
/**
|
|
|
|
* compile theme-chalk scss & minify
|
2021-08-04 22:53:32 +08:00
|
|
|
* not use sass.sync().on('error', sass.logError) to throw exception
|
2021-08-04 11:25:22 +08:00
|
|
|
* @returns
|
|
|
|
*/
|
2021-08-03 09:12:34 +08:00
|
|
|
function compile() {
|
|
|
|
return gulp
|
|
|
|
.src('./src/*.scss')
|
2021-08-04 22:53:32 +08:00
|
|
|
.pipe(sass.sync())
|
2021-08-03 09:12:34 +08:00
|
|
|
.pipe(autoprefixer({ cascade: false }))
|
|
|
|
.pipe(
|
|
|
|
cleanCSS({}, details => {
|
|
|
|
console.log(
|
|
|
|
`${chalk.cyan(details.name)}: ${chalk.yellow(
|
|
|
|
details.stats.originalSize / 1000,
|
|
|
|
)} KB -> ${chalk.green(details.stats.minifiedSize / 1000)} KB`,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.pipe(
|
|
|
|
rename(path => {
|
|
|
|
if (!noElPrefixFile.test(path.basename)) {
|
|
|
|
path.basename = `el-${path.basename}`
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest(distFolder))
|
|
|
|
}
|
|
|
|
|
2021-08-04 11:25:22 +08:00
|
|
|
/**
|
|
|
|
* copy font to lib/fonts
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
function copyFont() {
|
|
|
|
return gulp.src('./src/fonts/**').pipe(gulp.dest(`${distFolder}/fonts`))
|
2021-08-03 09:12:34 +08:00
|
|
|
}
|
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
const distBundle = path.resolve(buildOutput, './element-plus/theme-chalk')
|
|
|
|
|
2021-08-03 09:12:34 +08:00
|
|
|
/**
|
2021-08-24 13:36:48 +08:00
|
|
|
* copy from packages/theme-chalk/lib to dist/theme-chalk
|
2021-08-03 09:12:34 +08:00
|
|
|
*/
|
|
|
|
function copyToLib() {
|
2021-08-24 13:36:48 +08:00
|
|
|
return gulp.src(distFolder + '/**').pipe(gulp.dest(distBundle))
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy source file to packages
|
|
|
|
*/
|
|
|
|
|
|
|
|
function copySourceToLib() {
|
|
|
|
return gulp.src('./src/**').pipe(gulp.dest(path.resolve(distBundle, './src')))
|
2021-08-03 09:12:34 +08:00
|
|
|
}
|
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
|
|
|
|
export const build = gulp.series(
|
|
|
|
compile,
|
|
|
|
copyFont,
|
|
|
|
copyToLib,
|
|
|
|
copySourceToLib,
|
|
|
|
)
|
2021-08-03 09:12:34 +08:00
|
|
|
|
|
|
|
export default build
|