RequireJS搜索app.app而不是app.js(其中app.js是在data-main中指定的入口点) [英] RequireJS search for app.app instead of app.js (where app.js is entry point specified in data-main)

查看:47
本文介绍了RequireJS搜索app.app而不是app.js(其中app.js是在data-main中指定的入口点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我有一个使用requireJS的简单演示应用程序.加载 require.min.js 脚本时,它将尝试加载入口点脚本.但是,问题是,它尝试加载 localhost:8090/js/app.app 而不是 localhost:8090/js/app.js >并且失败.

演示:您可以在 GitHub 上看到整个应用./p>

===仅当您不喜欢GutHub时,这是我的代码===

文件结构

  ProjectRoot| -server.js|-公共/| -index.html| -js/| -app.js| -lib/| -require.min.js| -underscore.js| -backbone.js| -raphael.js| -app/|-.. 

server.js:

  var express = require('express');var app = express();app.use('/',express.static(__ dirname +'/public'));app.listen(8090); 

index.html:

 <!DOCTYPE html>< html><身体></body>< script src ="js/lib/require.min.js" data-main ="js/app.js"></script></html> 

app.js:

  require.config({路径:{'jquery':'lib/jquery','raphael':'lib/raphael'},垫片:{'lib/下划线':{出口:"_"},'lib/backbone':{部门:["lib/下划线","jquery"],出口:骨干"}}}); 

解决方案

应用中包含的您的require.js版本存在问题.使用CDN,它可以工作.

您代码中的版本与CDN上的实际.min版本不匹配,这意味着该版本已被修改并包含 .app

 <脚本src ="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js" data-main ="js/app"></脚本> 

Problem:

I have a trivial demo application which use requireJS. When require.min.js script loads, it tries to load entry-point script. But, the Problem is that instead of localhost:8090/js/app.js it tries to load localhost:8090/js/app.app and fails.

Demo: You can see the whole app at GitHub.

=== Only if you don't like GutHub, here's my code ===

File structure

ProjectRoot
 |-server.js
 |-public/
    |-index.html
    |-js/
       |-app.js
       |-lib/
          |-require.min.js
          |-underscore.js
          |-backbone.js
          |-raphael.js
       |-app/
          |-..

server.js:

var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/public'));
app.listen(8090);

index.html:

<!DOCTYPE html>
<html>
  <body>
  </body>
  <script src="js/lib/require.min.js" data-main="js/app.js"></script>
</html>

app.js:

require.config({
    paths: {
        'jquery': 'lib/jquery',
        'raphael': 'lib/raphael'
    },
    shim: {
        'lib/underscore': {
            exports: '_'
        },
        'lib/backbone': {
            deps: ["lib/underscore", "jquery"],
            exports: 'Backbone'
        }
    }
});

解决方案

There is a problem with your version of require.js included in the app. Use the CDN one and it works.

The version you have in your code does not match the actual .min version on the CDN which means it was modified and includes .app

<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js" data-main="js/app"></script>

这篇关于RequireJS搜索app.app而不是app.js(其中app.js是在data-main中指定的入口点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆