concatenation - Yeoman & RequireJS 使用动态生成的 HTML 构建?

标签 concatenation requirejs yeoman r.js

我正在尝试将由 Yeoman 生成/管理的 RequireJS 设置与后端的 Laravel PHP 框架相集成。除了 Yeoman/r.js 中用于我的 javascript 文件的构建步骤的串联部分外,一切都很好。

简而言之,我的问题是:Yeoman 中的 r.js 构建步骤查找带有 HTML 注释(如 <!-- build:js scripts/amd-app.js -->)的 index.html 文件。围绕 RequireJS 脚本标记,它启动了 RequireJS 优化器中的优化和连接例程。但是:我使用的是 Laravel 框架,所以没有 index.html,因为它是动态生成的。

我已经设法通过一个丑陋的 hack 并在应用程序目录文件中添加一个 index.html 来使这个过程工作,它只有:

<!-- build:js scripts/amd-app.js -->
<script data-main="scripts/main" src="scripts/vendor/require.js"></script>
<!-- endbuild -->

这让 Yeoman/r.js 找到一个带有适当标签和文件路径的 index.html 文件,对我的 AMD 模块进行所有出色的连接,并将其输出到 dist 目录中。

只是这是一个可怕的 hack,而且我敢肯定还有更简单的方法可以达到同样的目的。我认为这与编辑包含 Yeoman build设置以反射(reflect)上述信息的 Gruntfile 有关。我只是不确定如何:(

任何具有将 Yeoman/RequireJS 设置与后端框架集成的经验的人可能会有所帮助? (我想这个问题同样适用于 rails)。

最佳答案

如果你检查(至少在 Mac/linux 上):

/usr/local/lib/node_modules/yeoman/tasks/rjs.js

你会看到一行:

var appIndexPath  = path.resolve('mainFile' in options ? '../app/' + options.mainFile : '../app/index.html');

我猜你可以通过指定另一个 html 文件来启动这个过程

rjs: {
  // no minification, is done by the min task
  optimize: 'none',
  baseUrl: './scripts',
  wrap: true,
  name: 'main'
  mainFile: 'kickoff.html'
},

其实,

<!-- build:js scripts/amd-app.js -->

这是由 usemin 任务使用的,而不是 rjs。

要完全跳过 html 文件的需要,我将不得不深入挖掘。

关于concatenation - Yeoman & RequireJS 使用动态生成的 HTML 构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14009226/

相关文章:

angularjs - 在 AngularJS 的文件夹中加载 JavaScript 和 CSS 文件

javascript - requirejs 两次加载相同的模块

git - 哟jhipster : Failed to connect to "git://github.com"

python - 如何明智地连接多个列表元素

python - 如何将列表追加到 Python 中函数创建的列表中

javascript - 如何在 Webpack 中禁用捆绑以进行开发?

node.js - 在 nodejs 项目中以编程方式使用 Yeoman

javascript - Yeoman:LiveReload 与 Yeoman Watch

arrays - 如何在 bash 中连接数组?

mysql - 更新中间位被零屏蔽的列