2021-09-17 15:27:31 +08:00
|
|
|
import path from 'path'
|
2021-08-03 09:12:34 +08:00
|
|
|
import chalk from 'chalk'
|
2021-09-28 20:28:47 +08:00
|
|
|
import { src, dest, series, parallel } from 'gulp'
|
2021-08-03 09:12:34 +08:00
|
|
|
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'
|
2022-03-15 19:23:38 +08:00
|
|
|
import consola from 'consola'
|
|
|
|
import { epOutput } from '@element-plus/build'
|
2021-08-03 09:12:34 +08:00
|
|
|
|
2021-09-28 20:28:47 +08:00
|
|
|
const distFolder = path.resolve(__dirname, 'dist')
|
|
|
|
const distBundle = path.resolve(epOutput, 'theme-chalk')
|
2021-08-03 09:12:34 +08:00
|
|
|
|
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-09-28 20:28:47 +08:00
|
|
|
function buildThemeChalk() {
|
|
|
|
const sass = gulpSass(dartSass)
|
|
|
|
const noElPrefixFile = /(index|base|display)/
|
|
|
|
return src(path.resolve(__dirname, '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(
|
2021-09-04 19:29:28 +08:00
|
|
|
cleanCSS({}, (details) => {
|
2022-03-15 19:23:38 +08:00
|
|
|
consola.success(
|
2021-08-03 09:12:34 +08:00
|
|
|
`${chalk.cyan(details.name)}: ${chalk.yellow(
|
2021-09-04 19:29:28 +08:00
|
|
|
details.stats.originalSize / 1000
|
|
|
|
)} KB -> ${chalk.green(details.stats.minifiedSize / 1000)} KB`
|
2021-08-03 09:12:34 +08:00
|
|
|
)
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
2021-08-03 09:12:34 +08:00
|
|
|
)
|
|
|
|
.pipe(
|
2021-09-04 19:29:28 +08:00
|
|
|
rename((path) => {
|
2021-08-03 09:12:34 +08:00
|
|
|
if (!noElPrefixFile.test(path.basename)) {
|
|
|
|
path.basename = `el-${path.basename}`
|
|
|
|
}
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
2021-08-03 09:12:34 +08:00
|
|
|
)
|
2021-09-28 20:28:47 +08:00
|
|
|
.pipe(dest(distFolder))
|
2021-08-03 09:12:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-01-17 15:43:07 +08:00
|
|
|
* copy from packages/theme-chalk/dist to dist/element-plus/theme-chalk
|
2021-08-03 09:12:34 +08:00
|
|
|
*/
|
2021-09-28 20:28:47 +08:00
|
|
|
export function copyThemeChalkBundle() {
|
|
|
|
return src(`${distFolder}/**`).pipe(dest(distBundle))
|
2021-08-24 13:36:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy source file to packages
|
|
|
|
*/
|
|
|
|
|
2021-09-28 20:28:47 +08:00
|
|
|
export function copyThemeChalkSource() {
|
|
|
|
return src(path.resolve(__dirname, 'src/**')).pipe(
|
|
|
|
dest(path.resolve(distBundle, 'src'))
|
|
|
|
)
|
2021-08-03 09:12:34 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 20:28:47 +08:00
|
|
|
export const build = parallel(
|
|
|
|
copyThemeChalkSource,
|
|
|
|
series(buildThemeChalk, copyThemeChalkBundle)
|
|
|
|
)
|
2021-08-03 09:12:34 +08:00
|
|
|
|
|
|
|
export default build
|