Last active
June 18, 2018 07:49
-
-
Save khusamov/461cd31f9670f811c32071bb8a82a2a7 to your computer and use it in GitHub Desktop.
Gulpfile: Компиляция tsc плюс копирование файлов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Path from 'path'; | |
import * as Gulp from 'gulp'; | |
import * as GulpChanged from 'gulp-changed'; | |
import * as GulpTypeScript from 'gulp-typescript'; | |
/** | |
* Gulpfile введен в разработку пока лишь с одной целью: | |
* копировать JSON и XML файлы из src в dist. | |
*/ | |
const tsProject = GulpTypeScript.createProject('tsconfig.json'); | |
const tsConfig = require('./tsconfig.json'); | |
const tsConfigBaseUrl = tsConfig.compilerOptions.baseUrl; | |
const tsConfigOutDir = tsConfig.compilerOptions.outDir; | |
/** | |
* Копирование файлов JSON и XML из src в dist. | |
*/ | |
Gulp.task('copyFiles', function() { | |
const src = ( | |
['**/*.json', '**/*.xml'] | |
.map(dir => Path.join(tsConfigBaseUrl, 'lib', dir)) | |
); | |
return ( | |
Gulp.src(src, {base: tsConfigBaseUrl}) | |
.pipe(GulpChanged(tsConfigOutDir)) | |
.pipe(Gulp.dest(tsConfigOutDir)) | |
); | |
}); | |
/** | |
* Компиляция проекта в директорию dist. | |
*/ | |
Gulp.task('tsc', Gulp.parallel('copyFiles', function() { | |
return ( | |
tsProject.src() | |
.pipe(GulpChanged(tsConfigOutDir, {extension: '.js'})) | |
.pipe(tsProject()) | |
.pipe(Gulp.dest(tsConfigOutDir)) | |
); | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"main": "dist/index.js", | |
"types": "dist/index.d.ts", | |
"files": [ | |
"dist" | |
], | |
"scripts": { | |
"tsc": "gulp tsc" | |
}, | |
"devDependencies": { | |
"@types/gulp": "^4.0.5", | |
"@types/gulp-changed": "0.0.32", | |
"@types/gulp-typescript": "^2.13.0", | |
"gulp": "^4.0.0", | |
"gulp-changed": "^3.2.0", | |
"gulp-typescript": "^5.0.0-alpha.1", | |
"typescript": "^2.9.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment