了解r.js选项瓦特/咕噜&安培;骨干网和相对路径 [英] Understanding r.js options w/grunt & backbone and relative paths

查看:175
本文介绍了了解r.js选项瓦特/咕噜&安培;骨干网和相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何使用r.js.我不断收到抛出这样的模块路径不存在错误,或者文件被情人抛弃,他们不应该。

我有一个与字preSS集成在一个单一页面的应用程序。我已经通过我一般结构此骨干样板虽然我设置的东西,很不一样。我下面的文件结构如下所示。

 。主题文件夹
├──_assets
| ├──_Application
| | ├──CSS
| | ├──字体
| | ├──IMG
| | ├──_js
| | | ├──main.js //这是我require.js配置文件
| | | ├──_app //这里的地方样板结构进场
| | | ├──收藏
| | | ├──车型
| | | ├──路由器
| | | ├──模板
| | | ├──意见
| | | ├──库
| | | ├──公用事业
| | ├──SCSS
| | ├──视频
| └──打造//级联应用程序目录镜子
| └──gruntfile.js
| └──bower.json
| └──的package.json

要救我破译咕噜巨大文件的心痛。基本上我原本设定,让一切得到conatenated,变丑,并编译成build文件夹。我创建了一个简单的任务r.js只是测试的东西出来。我得到一个错误说我lodash库无法找到(在我的main.js文件第一条路径)。它认为lodash在资产/ lodash.js它忽略了我的main.js我的baseUrl属性(require.js配置)它的实际位置是资产/应用/ JS /库/ lodash.js。我requirejs任务如下:

  requirejs:{
          编译:{
            选项​​:{
              的baseUrl:./,
              mainConfigFile:应用程序/ JS / main.js
              名称:./application/js/main
              指出:./build/js/optimized.js
            }
          }
        }

我在最困难的时候搞清楚究竟RJS在做什么。当我期望它的工作它不是寻找合适的目录中的文件。当我将其配置为找到合适的文件,它复制了我的整个资产的文件夹并将其转储到我的生成文件夹......这已经引起了很多混乱,以什么都r.js在做什么,它要我输入这是什么选项​​。

这是我目前得到的错误:

 >>错误:ENOENT,没有这样的文件或目录
>> 路到主题文件夹,这里/资产/库/ lodash.js
>>在模块树:
>>应用程序/ JS / main.min


解决方案

在我看来,你给介绍,这应该工作:

  requirejs:{
  编译:{
    选项​​:{
      的baseUrl:应用程序/ JS /
      mainConfigFile:应用程序/ JS / main.js
      名称:主,
      指出:建立/ JS / optimized.js
    }
  }
}

I'm trying to figure out how to use r.js. I keep getting errors thrown such a module path does not exist, or files getting dumped where they shouldn't be.

I've got a single page application that is integrated with wordpress. I've adopted this backbone boilerplate for my general structure, although I've set things up quite different. My file structure is shown below.

.Theme Folder
├── _assets
|   ├── _application
|   |   ├── css
|   |   ├── fonts
|   |   ├── img
|   |   ├── _js
|   |   |   ├── main.js  //this is my require.js config file
|   |   |   ├── _app  //here's where the boilerplate structure comes into play
|   |   |       ├── collections
|   |   |       ├── models
|   |   |       ├── routers
|   |   |       ├── templates
|   |   |       ├── views
|   |   |   ├── libs
|   |   |   ├── utilities
|   |   ├── scss
|   |   ├── video
|   └── build  //Concatenated application directory mirror
|   └── gruntfile.js
|   └── bower.json
|   └── package.json

To save the heartache of deciphering my gigantic grunt file. Basically I originally set it up so that everything gets conatenated, uglified, and compiled into the build folder. I created a simple task for r.js to just test things out. I get an error saying my lodash library cannot be found (first path in my main.js file). It thinks lodash is in assets/lodash.js it's ignoring my baseUrl property in my main.js (require.js configuration) it's actual location is assets/application/js/libs/lodash.js. My requirejs task is below:

        requirejs: {
          compile: {
            options: {
              baseUrl: "./",
              mainConfigFile: "application/js/main.js",
              name: "./application/js/main",
              out: "./build/js/optimized.js"
            }
          }
        }

I'm having the hardest time figuring out what exactly rjs is doing. When I expect it to work it's not looking for the files in the right directory. When I configure it to find the right files it copies my entire assets folder and dumps it into my build folder... Which has caused a lot of confusion as to what all r.js is doing and what it wants me to input for it's options.

This is the error I am currently getting:

>> Error: ENOENT, no such file or directory
>> 'path-to-theme-folder-here/assets/libs/lodash.js'
>> In module tree:
>>     application/js/main.min

解决方案

It seems to me with the description you give, this should work:

requirejs: {
  compile: {
    options: {
      baseUrl: "application/js/",
      mainConfigFile: "application/js/main.js",
      name: "main",
      out: "build/js/optimized.js"
    }
  }
}

这篇关于了解r.js选项瓦特/咕噜&安培;骨干网和相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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