在Visual Studio Code中使用task.json转换打字稿和sass [英] Using tasks.json in Visual Studio Code to transpile both typescript and sass

查看:253
本文介绍了在Visual Studio Code中使用task.json转换打字稿和sass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将typescript和sass分别转换为javascript和css.在运行此task.json文件的那一刻,我的打字稿转换为javascript:

I want to transpile both typescript and sass to javascript and css respectively. At The moment running this tasks.json file transpiles my typescript to javascript:

{
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur.
    "showOutput": "silent",

    // args is the HelloWorld program to compile.
    "args": ["public/app/boot.ts"],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}

我只需要指定boot.ts,它将所有.ts文件转换为js.可能是因为我的boot.ts文件导入了我所有的ts文件.这是我的boot.ts文件:

I only need to specify boot.ts and it transpiles all .ts files to js. It might be because my boot.ts file imports all my ts files. Here is my boot.ts file:

import {bootstrap}    from 'angular2/platform/browser'
import {HelloWorld} from './hello_world'
import {TodoApp} from './todo_app'
bootstrap(HelloWorld);
bootstrap(TodoApp);

我想将代码添加到task.json文件中,以将sass转换为css.

I would like to add code into the tasks.json file that will transpile the sass to css.

这是我仅可以转换Sass的代码片段:

Here is a code snippet of what I could do to only transpile my sass:

{
    "version": "0.1.0",
    "command": "node-sass",
    "isShellCommand": true,
    "args": ["styles.scss", "styles.css"]
}

如何添加该代码段,以便同时转换sass和打字稿?

How do I add that code snippet so that it transpiles both the sass and the typescript?

此外,在创建它们时,是否要在task.json中的args数组中添加任何新的sass文件?

Also, Will I be wanting to add any new sass files to the args array in tasks.json as I create them?

推荐答案

您不能使用tsc命令执行此操作.使用npm代替.

you can't do this with the tsc command. use npm instead.

{
  "scripts": {
    "build": "tsc public/app/boot.ts && node-sass styles.scss styles.css"
  }
}

tasks.json

{
    "version": "0.1.0",
    "command": "npm",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["-s", "run"],
    "tasks": [{
      "taskName": "build",
      "problemMatcher": "$tsc",
      "isBuildCommand": true
    }]
}

这篇关于在Visual Studio Code中使用task.json转换打字稿和sass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆