【发布时间】:2014-07-29 20:12:00
【问题描述】:
我有一个带有 LESS 的 Angular JS 项目,并且正在使用 grunt 通过 grunt serve 编译和显示我的页面。但是,每次保存/编译 LESS 文件后,页面都会重新加载更改。如果我更改了页面上对象的状态并进行了 LESS 编辑,则页面重新加载会重新设置页面状态,我需要再次进行所有更改以查看我的 CSS 修复是否足够。
有没有办法在 LESS 文件编译时进行配置,在不加载整个 HTML 页面的情况下重新加载 CSS?
这是我的 Grunt.js 的连接部分:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
//hostname: 'localhost',
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.app %>'
]
}
},
dist: {
options: {
base: '<%= yeoman.dist %>'
}
}
},
还有更少的部分:
//LESS
less: {
theme: {
options: {
sourceMap: true,
sourceMapFilename: '.tmp/dist/css/theme.css.map',
sourceMapURL: 'theme.css.map',
outputSourceFiles: true
},
files: [{
".tmp/dist/css/theme.css": "<%= yeoman.less %>/theme.less"
}]
},
preview: {
options: {
sourceMap: true,
sourceMapFilename: '.tmp/live_preview/styles/main.css.map',
sourceMapURL: 'main.css.map',
outputSourceFiles: true
},
files: [{
".tmp/live_preview/styles/main.css": "<%= yeoman.preview %>/less/main.less"
}]
},
distTheme: {
options: {
compress: true,
yuicompress: true,
optimization: 2,
sourceMap: true,
sourceMapFilename: '<%= yeoman.dist %>/dist/css/theme.css.map',
sourceMapURL: 'theme.css.map',
outputSourceFiles: true
},
files: [{
"<%= yeoman.dist %>/dist/css/theme.css": "<%= yeoman.less %>/theme.less"
}]
}
},
【问题讨论】:
标签: angularjs gruntjs grunt-contrib-watch