【发布时间】:2014-04-05 19:26:14
【问题描述】:
我在为 Yeoman 创建自定义生成器时遇到问题。
生成的文件夹和文件的结构都很好。
如果我运行生成器,则没有错误并且所有文件都是正确的
问题在于创建 gruntfile.js。
如果我运行 grunt serve 我会收到错误 - 警告:找不到任务“express”。使用 --force 继续。
Gruntfile.js 有点像我在这里和那里找到的一些东西,所以它可以是任何东西。
有没有人知道任何解释如何做到这一点的教程,或者任何人都知道为什么这个 grunt 文件不起作用。
// Gruntfile with the configuration of grunt-express and grunt-open. No livereload yet!
module.exports = function (grunt) {
'use strict';
// Load Grunt tasks declared in the package.json file
//require('load-grunt-tasks')(grunt);
// Configure Grunt
grunt.initConfig({
// grunt-express serves the files from the folders listed in `bases`
// on specified `port` and `hostname`
express: {
all: {
options: {
port: 9000,
hostname: '0.0.0.0',
bases: [__dirname],
livereload: true
}
}
},
// grunt-watch monitors the projects files
watch: {
all: {
files: ['index.html', 'css/**/*.css', 'js/**/*.js'],
options: {
livereload: true
}
}
},
// grunt-open will open your browser at the project's URL
open: {
all: {
// Gets the port from the connect configuration
path: 'http://localhost:<%= express.all.options.port%>'
}
}
});
// Creates the `server` task
grunt.registerTask('serve', [
'express',
'open',
'watch'
]);
};
【问题讨论】: