我正在尝试设置我的环境,以便能够将编译器绑定到: -编译(包括.ts转译)后,将一些文件复制到另一个文件夹中 -在启动/调试之前始终编译(并复制文件)
每次启动编译时,我都可以使用gulp复制文件
const gulp = require('gulp');
const gulpTs = require('gulp-typescript');
const path = require('path');
const fs = require('fs');
const colors = require('colors');
const packageJson = JSON.parse(fs.readFileSync('./package.json'));
const tsProject = gulpTs.createProject('tsconfig.json');
const copyTs = true;
const copyDTs = false;
const copyJs = false;
const copyToDirs = [
"path1",
"path2",
"path3"]
.map(dirPath => path.join(dirPath, packageJson.name));
gulp.task('transpile-and-copy', function () {
tsProject.options.declaration = true;
const rawTs = tsProject.src();
const compiledTs = tsProject
.src()
.pipe(tsProject());
let missionName = "Copy of " + packageJson.name;
copyToDirs.forEach((dirPath) => {
try {
process.stdout.write('Copying'.yellow + ' to: ' + dirPath + ' ...');
if (copyTs)
rawTs.pipe(gulp.dest(dirPath));
if (copyJs)
compiledTs.js.pipe(gulp.dest(dirPath));
if (copyDTs)
compiledTs.dts.pipe(gulp.dest(dirPath));
console.log(" DONE".green);
} catch (error) {
console.log(" FAILED".red);
console.log((missionName + " failed - reason: " + error).red);
}
});
console.log((missionName + ' completed').green);
});
带有任务(tasks.json)
{
"version": "2.0.0",
"tasks": [
{
"identifier": "transpile-and-copy",
"type": "gulp",
"task": "transpile-and-copy",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
但是如何在每个F5之前编译并复制文件?
谢谢大家!
答案 0 :(得分:0)
在launch.json文件中添加一个prelaunchtask
选项。
无论您要使用哪种启动配置,例如:
launch.json
{
"name": "Chrome : Launch with sourcemaps",
"preLaunchTask": "transpile-and-copy",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"runtimeArgs": [
"--remote-debugging-port=9222"
]
},