【问题标题】:Yeoman & RequireJS build with dynamically generated HTML?Yeoman 和 RequireJS 使用动态生成的 HTML 构建?
【发布时间】:2012-12-23 06:51:38
【问题描述】:

我正在尝试将由 Yeoman 生成/管理的前端上的 RequireJS 设置与后端的 Laravel PHP 框架集成。除了在 Yeoman / r.js 中为我的 javascript 文件构建步骤的连接部分之外,一切都是金色的。

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

我已经设法通过做一个丑陋的 hack 并在 app 目录文件中添加一个 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 构建设置的 Gruntfile 以反映上述信息有关。我只是不确定如何:(

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

【问题讨论】:

    标签: concatenation requirejs yeoman r.js


    【解决方案1】:

    如果你检查(至少在 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 文件的需求,我必须深入挖掘。

    【讨论】:

      猜你喜欢
      • 2013-03-14
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多