在scss上重新加载页面保存

时间:2016-09-27 21:01:24

标签: angular gulp gulp-livereload

我正在使用官方Quick start指南与Angular 2一起玩。

package.json文件中的Dev Dependencies允许通过保存html文件进行实时重新加载。

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

我想要的是使用Angular 2的html实时重新加载来绑定Gulp的scss实时重新加载。我的意思是当我在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"
 }
}

1 个答案:

答案 0 :(得分:0)

首先,您必须告诉您需要注意scss文件中的更改。

在你 gulpfile.js

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

其次,你必须同时开始使用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"
 },