我正在Angular2
中设置一个Visual studio code
项目,其中包含Sass
个样式的文件。但我似乎无法以正确的方式编译。
我正在尝试在我的src目录中编译(保存!)所有.ts文件和.scss。 .scss文件和.ts放在src(我的主)目录的子目录中。我将所有_.scss文件包含在一个.scss文件中,我想将其编译为一个css文件。我还想将所有.ts文件编译成一个.js文件(不缩小)
打字稿编译器
对于打字稿我使用的是Visual Studio代码的默认$tsc
编译器
Sass编译器
对于Sass文件(.scss)我正在使用node-sass V4.5.1
设置
我在tasks.json中有以下设置:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "always",
"args": ["-s", "run"],
"tasks": [{
"taskName": "buildAndWatch",
"problemMatcher": "$tsc",
"isBuildCommand": true
}]
}
我的package.json
中有以下代码 "scripts": {
"buildAndWatch": "tsc && node-sass --watch"
}
我的tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"outDir": "build/",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"removeComments": true,
"moduleResolution": "node",
"typeRoots": [
"node_modules/@types"
],
"watch": true
},
"exclude": [
"node_modules",
"build"
]
}
问题
可以找到一个示例here,但是那个人不会观看并重新编译文件
几乎得到它今天我发现了如何观看和构建我的sass和我的打字稿。为此,我使用以下npm脚本:
"scripts": {
"Start:Development":"npm run Build:Typescript && npm run Watch:Sass",
"Build:Typescript": "tsc",
"Build:Sass": "node-sass ./src/assets/scss/main.scss ./src/assets/css/stylesheet.css",
"Watch:Sass": "npm run Build:Sass && npm run Build:Sass -- -w"
}
我打电话给Start:Development
,剩下的就是npm。但是,我还有一个问题。 vs代码赢了两个手表。我可以将Build:Typescript
和Watch:Sass
彼此分开,但不能同时运行。如果我尝试那么只会编译我的打字稿。有人可以帮我这个吗?