【问题标题】:R.js(require.js) cause ReferenceError: define is not defined [duplicate]R.js(require.js)导致ReferenceError:未定义定义[重复]
【发布时间】:2016-03-21 05:20:34
【问题描述】:

我通过r.js -o build.js创建了require.js项目

但是,它给了我控制台上的异常

define('hbs/下划线',[],function() {

这是生成的app.min.js

https://gist.github.com/poc7667/ecf36474b68799ebb29d

有解决问题的办法吗?我使用选项wrap: true 是为了避免与其他脚本冲突,这会给我常见的mismatch 异常

HTML

      <script type="text/javascript" src="js/app.min.js" ></script>

build.js

{
    name: "app.main.js",
    mainConfigFile: 'app.main.js',
    out: "./app.min.js",
    optimize: 'none',
    wrap: true,
    include: [ 'app.main' ],
    insertRequire: ["app.main"],
}

app.main.js

requirejs.config({
    paths: {
        jquery: './vendor/js/jquery-2.1.1.min',
        underscore: './vendor/js/underscore-min',
        backbone: './vendor/js/backbone-min',
        json2: './vendor/js/hbs/hbs/json2',
        hbs: './vendor/js/hbs/hbs',
        handlebars: './vendor/js/handlebars-v4.0.5',
        text: './vendor/js/text',
    },
    hbs: { // optional
        helpers: true,            // default: true
        templateExtension: 'hbs', // default: 'hbs'
        partialsUrl: ''           // default: ''
    },

    shim: {
        handlebars: {
            exports: 'Handlebars'
        },
        backbone: {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        },
        underscore: {
            exports: '_'
        },
        'jquery': {
            'exports' : '$'
        }
    },

});

require(["require", "app"],function(Req, App ){
    $("#sample_app_comments_plugin").hide();
    $('head').append('<link rel="stylesheet" href='+cfg.css_style_link+' type="text/css" />');
    return App.initialize();


});

hbs.js

    define(['hbs/handlebars', 'hbs/underscore', 'hbs/json2'], function (Handlebars, _, JSON) {
      function precompile(string, _unused, options) {
        var ast, environment;
    ....

【问题讨论】:

    标签: javascript requirejs r.js


    【解决方案1】:

    您可能在页面上没有 requirejs。

    您可以使用 almondjs,这将允许它只包含您的 app.js 文件。 https://github.com/requirejs/almond

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-27
      • 2016-05-09
      • 1970-01-01
      • 2023-04-11
      • 2012-08-24
      • 2012-09-07
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多