2021-08-24 13:36:48 +08:00
|
|
|
import gulp from 'gulp'
|
|
|
|
import ts from 'gulp-typescript'
|
|
|
|
import path from 'path'
|
|
|
|
import through2 from 'through2'
|
|
|
|
|
|
|
|
const output = path.resolve(__dirname, '../dist/styles')
|
|
|
|
|
|
|
|
const tsProject = ts.createProject('tsconfig.json', {
|
|
|
|
declaration: true,
|
|
|
|
target: 'ESNEXT',
|
|
|
|
skipLibCheck: true,
|
|
|
|
module: 'commonjs',
|
|
|
|
})
|
|
|
|
|
|
|
|
const rewriter = () => {
|
|
|
|
return through2.obj(function(file, _, cb) {
|
2021-08-24 16:52:44 +08:00
|
|
|
const compIdentifier = new RegExp('@element-plus/components', 'g')
|
2021-08-24 13:36:48 +08:00
|
|
|
const compReplacer = '../../../components'
|
2021-08-24 16:52:44 +08:00
|
|
|
const themeIdentifier = new RegExp('@element-plus/theme-chalk', 'g')
|
2021-08-24 13:36:48 +08:00
|
|
|
const themeReplacer = '../../../../theme-chalk'
|
|
|
|
file.contents = Buffer.from(
|
|
|
|
file.contents
|
|
|
|
.toString()
|
2021-08-24 16:52:44 +08:00
|
|
|
.replace(compIdentifier, compReplacer)
|
|
|
|
.replace(themeIdentifier, themeReplacer),
|
2021-08-24 13:36:48 +08:00
|
|
|
)
|
|
|
|
cb(null, file)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const inputs = '../packages/components/**/style/*.ts'
|
|
|
|
|
|
|
|
function compileEsm() {
|
|
|
|
return gulp
|
|
|
|
.src(inputs)
|
|
|
|
.pipe(rewriter())
|
|
|
|
.pipe(tsProject())
|
|
|
|
.pipe(gulp.dest(path.resolve(output, 'lib')))
|
|
|
|
}
|
|
|
|
|
|
|
|
function compileCjs() {
|
|
|
|
return gulp
|
|
|
|
.src(inputs)
|
|
|
|
.pipe(rewriter())
|
|
|
|
.pipe(
|
|
|
|
ts.createProject('tsconfig.json', {
|
|
|
|
declaration: true,
|
|
|
|
target: 'ESNEXT',
|
|
|
|
skipLibCheck: true,
|
|
|
|
module: 'ESNEXT',
|
|
|
|
})(),
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest(path.resolve(output, 'es')))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const build = gulp.series(compileEsm, compileCjs)
|
|
|
|
|
|
|
|
export default build
|