代码之家  ›  专栏  ›  技术社区  ›  Sergio

在vscode中编译(传输)、复制文件、调试链

  •  0
  • Sergio  · 技术社区  · 8 年前

    我正在尝试设置我的环境,以便能够将编译绑定到: -在启动/调试之前,始终编译(并复制文件)

    每次启动compile时,我都可以使用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);
    });
    

    {
        "version": "2.0.0",
        "tasks": [
            {
                "identifier": "transpile-and-copy",
                "type": "gulp",
                "task": "transpile-and-copy",
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    但是 ?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Mark    8 年前

    添加 prelaunchtask 选项在launch.json文件中。

    在您想要的任何启动配置中,例如:

    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"
         ]
    },
    
    推荐文章