【发布时间】:2014-11-06 15:38:57
【问题描述】:
我确定我遗漏了一些东西。我正在尝试将在一个项目上工作的 gruntfile 重新用于一个新项目。该文件运行并启动一个服务器实例,但不在我设置的端口上,并且它没有“进入监视模式”。
grunt 命令导致
Opening server for /Users/stevelombardi/Documents/command-central/cc on port 1337.
确实,如果我打开浏览器到http://127.0.0.1:1337,我会看到主页。但是,我希望端口 9000(请参阅 gruntfile)并让它监视我的文件的更改。
这里是 gruntfile。我在这里搞砸了什么?
'use strict';
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
options: {
livereload: true,
},
html: {
files: [
'{,*/}*.html'
]
},
sass: {
files: ['sass/{,*/}*.scss'],
tasks: ['sass:app'],
options: {
livereload: false
}
},
js: {
files: ['scripts/{,*/}*.js']
},
css: {
files: ['css/*.css'],
},
gruntfile: {
files: ['Gruntfile.js']
}
},
sass: {
app: {
options: {
style: 'compact',
sourcemap: 'auto'
},
files: {
'css/styles.css': 'sass/styles.scss',
}
}
},
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '127.0.0.1',
livereload: 35729
},
livereload: {
options: {
open: true,
base: ''
}
},
livepreview: {
options: {
open: true,
base: ''
}
}
}
});
grunt.registerTask('default', [
'sass',
'connect:livepreview',
'watch'
]);
};
【问题讨论】:
-
尝试添加 grunt.loadNpmTasks('grunt-contrib-watch');
-
你可能还需要 grunt.loadNpmTasks('grunt-sass');
-
这是一个自动加载所有 grunt 模块的 grunt 模块:
require('load-grunt-tasks')(grunt);所以我不必单独调用它们。此外,这些任务不会引发错误——就像它们的模块没有加载时那样。
标签: javascript node.js gruntjs