简体   繁体   English

如何在早午餐中使用jQuery

[英]How to use jquery with brunch

I'm trying to setup a backbone application, and I get a "$ is not defined" error. 我正在尝试设置主干应用程序,但出现“未定义$”错误。

Tree : 
      app :/
           app.js
           js :/
               jquery.js
               underscore.js
               backbone.js

I have a config.coffee file for brunch : 我有一个用于早午餐的config.coffee文件:

exports.config =   paths:
    public: 'www'   files:
    javascripts:
      joinTo:
        'js/atf.js': /^app/
      order:
        before: [
          'app/js/jquery-2.0.2.min.js',
          'app/js/underscore.js',
          'app/js/backbone.js'
        ]

    stylesheets:
      joinTo:
        'css/atf.css': /^app/

    templates:
      joinTo: 'js/atf.js'

My index.html file : 我的index.html文件:

<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="fr"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="fr"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="fr"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="fr" x-manifest="/manifest.appcache"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Test</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <link rel="stylesheet" type="text/css" media="all" href="/css/atf.css?v=2">
  <script src="/socket.io/socket.io.js"></script>
  <script src="/js/atf.js?v=3"></script>
  <script>require('app');</script>
</head>
<body></body>
</html>

And my app.js file just to make a test : 而我的app.js文件只是为了进行测试:

$(function(){
    alert('test');
});

Anyone can help me ? 有人可以帮助我吗? Thanks ! 谢谢 !

Move files from app/js to vendor (create this directory). 将文件从app/js移至vendor (创建此目录)。 And change javascripts.joinTo to the same one you are using in templates . 然后将javascripts.joinTo更改为您在templates中使用的同一地址。

That should do the trick. 这应该够了吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM