gulpfile.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import path from 'path'
  2. import chalk from 'chalk'
  3. import { dest, parallel, series, src } from 'gulp'
  4. import gulpSass from 'gulp-sass'
  5. import dartSass from 'sass'
  6. import autoprefixer from 'gulp-autoprefixer'
  7. import cleanCSS from 'gulp-clean-css'
  8. import rename from 'gulp-rename'
  9. import consola from 'consola'
  10. import { epOutput } from '@kankan/build-utils'
  11. const distFolder = path.resolve(__dirname, 'dist')
  12. const distBundle = path.resolve(epOutput, 'theme-chalk')
  13. /**
  14. * compile theme-chalk scss & minify
  15. * not use sass.sync().on('error', sass.logError) to throw exception
  16. * @returns
  17. */
  18. function buildThemeChalk() {
  19. const sass = gulpSass(dartSass)
  20. const noElPrefixFile = /(index|base|display)/
  21. return src(path.resolve(__dirname, 'src/*.scss'))
  22. .pipe(sass.sync())
  23. .pipe(autoprefixer({ cascade: false }))
  24. .pipe(
  25. cleanCSS({}, details => {
  26. consola.success(`${chalk.cyan(details.name)}: ${chalk.yellow(details.stats.originalSize / 1000)} KB -> ${chalk.green(details.stats.minifiedSize / 1000)} KB`)
  27. })
  28. )
  29. .pipe(
  30. rename(path => {
  31. if (!noElPrefixFile.test(path.basename)) {
  32. path.basename = `ui-${path.basename}`
  33. }
  34. })
  35. )
  36. .pipe(dest(distFolder))
  37. }
  38. /**
  39. * Build dark Css Vars
  40. * @returns
  41. */
  42. function buildDarkCssVars() {
  43. const sass = gulpSass(dartSass)
  44. return src(path.resolve(__dirname, 'src/dark/css-vars.scss'))
  45. .pipe(sass.sync())
  46. .pipe(autoprefixer({ cascade: false }))
  47. .pipe(
  48. cleanCSS({}, details => {
  49. consola.success(`${chalk.cyan(details.name)}: ${chalk.yellow(details.stats.originalSize / 1000)} KB -> ${chalk.green(details.stats.minifiedSize / 1000)} KB`)
  50. })
  51. )
  52. .pipe(dest(`${distFolder}/dark`))
  53. }
  54. /**
  55. * copy from packages/theme-chalk/dist to dist/element-plus/theme-chalk
  56. */
  57. export function copyThemeChalkBundle() {
  58. return src(`${distFolder}/**`).pipe(dest(distBundle))
  59. }
  60. /**
  61. * copy source file to packages
  62. */
  63. export function copyThemeChalkSource() {
  64. return src(path.resolve(__dirname, 'src/**')).pipe(dest(path.resolve(distBundle, 'src')))
  65. }
  66. // buildDarkCssVars
  67. export const build = parallel(copyThemeChalkSource, series(buildThemeChalk, copyThemeChalkBundle))
  68. export default build