【问题标题】:Yeoman custom generatorYeoman 自定义生成器
【发布时间】: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'
      ]);
    };

【问题讨论】:

    标签: gruntjs yeoman


    【解决方案1】:

    我认为您需要从 //require('load-grunt-tasks')(grunt) 中删除斜杠,以便它将加载 package.json 中的依赖项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多