首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用require js和grunt.js -错误缺少“名称”、“包含”或“模块”选项。

使用require js和grunt.js -错误缺少“名称”、“包含”或“模块”选项。
EN

Stack Overflow用户
提问于 2013-07-26 20:57:20
回答 1查看 6.7K关注 0票数 9

我的Gruntfile.js文件:

代码语言:javascript
复制
module.exports = function (grunt) {
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        requirejs : {
            compile: {
                options: {
                    baseUrl: "public_html/js",
                    mainConfigFile: "public_html/js/config.js",
                    out: "public_html/app.min.js"
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-requirejs');

    grunt.registerTask('default', ['requirejs']);
};

我的config.js文件:

代码语言:javascript
复制
'use strict';

require.config({
    deps: ['main'],
    paths: {
        jquery: 'vendor/jquery',
        jquery_tokeninput: 'vendor/jquery.tokeninput',
        underscore: 'vendor/underscore',
        backbone: 'vendor/backbone'
    },
    shim: {
        jquery: [],
        jquery_tokeninput: {
            deps: ['jquery']
        },
        backbone: {
            deps: ['vendor/underscore', 'vendor/jquery', 'vendor/jquery.tokeninput'],
            exports: 'Backbone'
        },
        underscore: {
            exports: '_'
        }
    }
});

require(['views/app'], function(AppView) {
  new AppView;
});

当我运行grunt requirejs it错误时:

代码语言:javascript
复制
Running "requirejs:compile" (requirejs) task
[Error: Error: Missing either a "name", "include" or "modules" option at function.build.createConfig (D:\project\node_modules\grunt-contrib-requirejs\node_modules\requirejs\bin\r.js:24829:19)]

第一次使用gruntjs和requirejs时,不太清楚为什么会出现错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-26 21:15:13

更新grunt.js文件以使用名称:

代码语言:javascript
复制
module.exports = function (grunt) {
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        requirejs : {
            compile: {
                options: {
                    name: "views/app",
                    baseUrl: "public_html/js",
                    mainConfigFile: "public_html/js/config.js",
                    out: "public_html/app.min.js"
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-requirejs');

    grunt.registerTask('default', ['requirejs']);
};

并从config.js中删除以下内容

代码语言:javascript
复制
require(['views/app'], function(AppView) {
  new AppView;
});
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17890927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档