在grunt-contrib-requirejs中使用杏仁 [英] Using almond with grunt-contrib-requirejs

查看:158
本文介绍了在grunt-contrib-requirejs中使用杏仁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置一个使用requirejs和杏仁的grunt文件。 文档表明它应该很容易,并且遵循他们的主导,我试过:

  requirejs:{
编译:{
options:{
aseUrl:tmp,
mainConfigFile: tmp / main.js,
name:../bower_components/almond/almond,
out:tmp /<%= pkg.name%> .js
}
}
}

不幸的是,这种方法编译 almond.js 而不是我的实际来源。我错了吗?我该如何自动将almond和requirejs一起使用? 解决方案

诀窍是使用 include

  requirejs:{
编译:{
options:{
baseUrl:tmp,
mainConfigFile:tmp / main.js,
include:main,
name:../bower_components/almond/almond,
out:tmp /<%= pkg.name%> .js
}
}
}

其中 main 是require.js文件您通常会这样调用:

 < script data-main =scripts / mainsrc =scripts / require。 JS>< /脚本> 


I'm trying to set up a gruntfile that utilizes requirejs and almond. The docs suggest it should be really easy, and following their lead, I tried:

requirejs: {
  compile: {
    options: {
      baseUrl: "tmp",
      mainConfigFile: "tmp/main.js",
      name: "../bower_components/almond/almond",
      out: "tmp/<%= pkg.name %>.js"
    }
  }
}

Unfortunately, this approach compiles almond.js rather than my actual source. Am I getting something wrong? How do I automate almond along with requirejs?

解决方案

The trick is to use include:

requirejs: {
  compile: {
    options: {
      baseUrl: "tmp",
      mainConfigFile: "tmp/main.js",
      include: "main",
      name: "../bower_components/almond/almond",
      out: "tmp/<%= pkg.name %>.js"
    }
  }
}

Where main is the require.js file you would typically call like so:

<script data-main="scripts/main" src="scripts/require.js"></script>

这篇关于在grunt-contrib-requirejs中使用杏仁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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