2016-09-27 42 views
2

我正在玩Angular 2,使用官方Quick start指南。在scss上重新加載頁面保存

Dev package.json文件的依賴項允許通過保存html文件實時重新加載。

我也使用Gulp和生活重新加載scss來裝飾我的東西的CSS。

我想要的是將Gulp的scss live reload與Angular 2的html live reload進行綁定。我的意思是,當我將更改保存在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" 
} 
} 
+0

本教程介紹瞭如何編譯SCSS的CSS,甚至做現場重裝:https://medium.com/@lampt2509/set-up-persistence-scss -from-chrome-devtools-for-angular-220ce0818568 –

回答

0

首先,你必須告訴你一口看在你scss文件更改。

在你gulpfile.js

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

其次,你必須開始這一口concurrenctly腕錶以TSC手錶和精簡版服務器。

在你的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" 
}, 
+0

是的,但實際上它不會改變任何東西。它允許使用gulp或html(ts/js ...)在終端 –

+0

中使用npm start命令更改scss文件。默認情況下,lite-server可能不會查找css文件中的更改。您是否嘗試自定義lite-server配置? –