2

我正在使用官方快速入门指南玩 Angular 2。

package.json 文件中的开发依赖项允许通过保存 html 文件进行实时重新加载。

我还使用 Gulp 和 live reload scss to css 来装饰我的东西。

我想要的是将 Gulp 的 scss 实时重载与 Angular 2 的 html 实时重载绑定。我的意思是当我在 scss 或 html 文件中保存更改时,我希望这些更改通过实时重新加载来完成。

现在,我只能通过在终端中运行 Gulp 命令或 npm start 命令来单独更改 scss 和 html。

我的 gulpfile.js 代码:

var gulp = require('gulp');
var sass = require('gulp-sass');

gulp.task('sass', function(){
      return gulp.src('app/assets/scss/styles.scss')
   .pipe(sass())
   .pipe(gulp.dest('app/assets/css'))
});

我的 package.json 代码:

{
 "name": "app",
 "version": "1.0.0",
 "scripts": {
    "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
 },
 "license": "ISC",
 "dependencies": {
   "@angular/common": "2.0.0",
   "@angular/compiler": "2.0.0",
   "@angular/core": "2.0.0",
   "@angular/forms": "2.0.0",
   "@angular/http": "2.0.0",
   "@angular/platform-browser": "2.0.0",
   "@angular/platform-browser-dynamic": "2.0.0",
   "@angular/router": "3.0.0",
   "@angular/upgrade": "2.0.0",
   "core-js": "^2.4.1",
   "reflect-metadata": "^0.1.3",
   "rxjs": "5.0.0-beta.12",
   "systemjs": "0.19.27",
   "zone.js": "^0.6.23",
   "angular2-in-memory-web-api": "0.0.20",
   "bootstrap": "^3.3.6"
 },
 "devDependencies": {
   "browser-sync": "^2.16.0",
   "concurrently": "^2.2.0",
   "gulp": "^3.9.1",
   "gulp-sass": "^2.3.2",
   "lite-server": "^2.2.2",
   "typescript": "^2.0.2",
   "typings": "^1.3.2"
 }
}
4

1 回答 1

0

首先,你必须告诉你的 gulp 观察你的scss文件中的变化。

在你gulpfile.js

//Watch task
gulp.task('sassWatch',function() {
    gulp.watch('app/assets/scss/**/*.scss',['sass']);
});

其次,您必须同时启动这个 gulp watch 到 tsc watch 和 lite 服务器。

在你的package.json

"scripts": {
    "start": "concurrently \"npm run sass:w\" \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",

    "postinstall": "typings install",

    "tsc": "tsc",
    "tsc:w": "tsc -w",

    "sass": "gulp sass",
    "sass:w": "gulp sassWatch", 

    "typings": "typings"
 },
于 2016-09-27T21:15:12.017 回答