如何在Grunt-contrib-requirejs优化器中使用Requirejs-handlebars?

raptoria7

我目前正在使用Grunt-contrib-requirejs优化器,这样我的最终包结构基本上如下所示:

Public/
  css
  js
   -myapp.js
   -require.js

我想使用requirejs-handlebars渲染模板(也可以在服务器端使用Express3-handlebars)。我已经使用NPM包requirejs-handlebars了,但是仅当我通过以下行在Express服务器中公开该模块时:

app.use('/node_modules/handlebars/dist/',  express.static(path.join(__dirname, './node_modules/handlebars/dist/' )));

没有此修复程序,加载应用程序时出现以下控制台错误:

GET http:// localhost:3300 / node_modules / handlebars / dist / handlebars.runtime.amd.js require.js:166未捕获的错误:handlebars.runtime的脚本错误

我猜这个错误是我最终的构建结构和我的需求优化程序的结果。由于明显的原因,该脚本不存在,因为我的最终构建结构未包含该脚本。我想我想要的是不必使用快速中间件包含handlebars.runtime,也不必将其与最终的myapp.js合并(我不确定这样做的最佳方法是什么)。有任何想法吗?对不起,n00bness ...任何建议将不胜感激!

谢谢!

我的main.js文件如下所示:

   require.config({
  shim: {
    jquery: {
      exports: '$'
    },
    underscore: {
      exports: '_'
    },
    backbone: {
      deps: [
        'jquery',
        'underscore'
      ],
      exports: 'Backbone'
    },
    marionette: {
      deps: [
        'jquery',
        'underscore',
        'backbone'
      ],
      exports: 'Marionette'
    },
    bootstrap: {
      deps: [
        'jquery'
      ]
    }
  },
  paths: {
    backbone: '../../bower_components/backbone/backbone',
    marionette: '../../bower_components/backbone.marionette/lib/backbone.marionette',
    jquery: '../../bower_components/jquery/jquery',
    underscore: '../../bower_components/underscore/underscore',
    requirejs: '../../bower_components/requirejs/require',
    text: '../../node_modules/requirejs-text/text',
    hb: '../../node_modules/requirejs-handlebars/hb',
    'handlebars.runtime': '../../node_modules/handlebars/dist/handlebars.runtime.amd',
  },
  packages: [
    {
      name: 'handlebars',
      location: '../../node_modules/handlebars/dist/amd',
      main: './handlebars'
    }
  ]
});


require([
  './app',
], function(App){

  'use strict';
  var myapp = new App();
  myapp.start();

});

我的Gruntfile:

     requirejs: {
          compile: {
            options: {
              baseUrl: "client/src",
              optimize: '', //uglify
              mainConfigFile:'client/src/main.js',
              name: "main",
              out: "build/app.js",
              removeCombined: true,
              logLevel: 0,
              findNestedDependencies: true,
              fileExclusionRegExp: /^\./,
              inlineText: true,
            }
          },
     },
安德鲁·拉弗斯(Andrew Lavers)

似乎笨拙的requirejs没有内联handlebars.runtime模块,这就是为什么您必须在快速代码中为其添加该远程路由的原因。

我设法通过声明handlebars和handlebars.runtime的路径来修复它,并且还必须对它们进行填充。因此,我的main.js看起来像这样:

paths: {
    'handlebars.runtime': '../bower_components/handlebars/handlebars.runtime',
    handlebars: '../bower_components/handlebars/handlebars',
    hbs: '../bower_components/requirejs-handlebars/hb',
},
shim: {
    'handlebars.runtime': {
        exports: 'handlebars.runtime'
    },
    handlebars: {
        deps: ['handlebars.runtime']
    },
}

现在,当我咕unt咕build地编译时,我可以看到handlebars和handlebars.runtime都内联到我的app.js中。那应该使您不必暴露来自express的node_modules目录。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Grunt-contrib-requirejs优化器中使用Requirejs-handlebars?

来自分类Dev

使用grunt-contrib-handlebars版本问题预编译车把

来自分类Dev

如何在Play框架中使用RequireJS优化器?

来自分类Dev

Gruntfile with grunt-contrib-watch, browserify, and hbsfy (handlebars) - Automate transform

来自分类Dev

将杏仁与grunt-contrib-requirejs一起使用

来自分类Dev

grunt-contrib-requirejs敲除组件问题

来自分类Dev

如何在grunt-requirejs中使用Closure Compiler?

来自分类Dev

如何在Ubuntu服务器12.04 64中安装grunt-contrib-qunit?

来自分类Dev

如何仅在需要时使用grunt-contrib-watch和grunt-contrib-coffee编译CoffeeScript?

来自分类Dev

如何在不同的文件上使用不同的grunt-contrib-less选项

来自分类Dev

在凉亭中使用grunt-contrib-concat

来自分类Dev

如何使用grunt-contrib-uglify也gzip js文件?

来自分类Dev

如何使用grunt http服务器访问区域设置json文件(grunt-contrib-connect)

来自分类Dev

grunt-contrib-requirejs任务停止Grunt且没有错误

来自分类Dev

如何在Handlebars循环中使用{{this}}访问数组内容?

来自分类Dev

requirejs优化器-如何更改优化的模块名称

来自分类Dev

使用grunt-contrib-connect和grunt-contrib-watch进行实时重载

来自分类Dev

如何使用Javascript使用Handlebars.registerPartial

来自分类Dev

如何禁用grunt-contrib-cssmin联合?

来自分类Dev

如何使用Handlebars遍历JSON结构

来自分类Dev

如何使用Handlebars和YUI设置onclick?

来自分类Dev

带RequireJS和BackboneJS的HandleBars编译

来自分类Dev

如何使用rocket_contrib Json?

来自分类Dev

如何在带有Requirejs的Typescript中使用模块/类

来自分类Dev

使用globlob模式时grunt-contrib-concat的奇怪行为

来自分类Dev

使用grunt-contrib-connect指定标题

来自分类Dev

阻止Grunt Contrib Uglify删除未使用的Javascript

来自分类Dev

使用globlob模式时grunt-contrib-concat的奇怪行为

来自分类Dev

无法使用grunt-contrib-cssmin创建缩小的CSS文件

Related 相关文章

  1. 1

    如何在Grunt-contrib-requirejs优化器中使用Requirejs-handlebars?

  2. 2

    使用grunt-contrib-handlebars版本问题预编译车把

  3. 3

    如何在Play框架中使用RequireJS优化器?

  4. 4

    Gruntfile with grunt-contrib-watch, browserify, and hbsfy (handlebars) - Automate transform

  5. 5

    将杏仁与grunt-contrib-requirejs一起使用

  6. 6

    grunt-contrib-requirejs敲除组件问题

  7. 7

    如何在grunt-requirejs中使用Closure Compiler?

  8. 8

    如何在Ubuntu服务器12.04 64中安装grunt-contrib-qunit?

  9. 9

    如何仅在需要时使用grunt-contrib-watch和grunt-contrib-coffee编译CoffeeScript?

  10. 10

    如何在不同的文件上使用不同的grunt-contrib-less选项

  11. 11

    在凉亭中使用grunt-contrib-concat

  12. 12

    如何使用grunt-contrib-uglify也gzip js文件?

  13. 13

    如何使用grunt http服务器访问区域设置json文件(grunt-contrib-connect)

  14. 14

    grunt-contrib-requirejs任务停止Grunt且没有错误

  15. 15

    如何在Handlebars循环中使用{{this}}访问数组内容?

  16. 16

    requirejs优化器-如何更改优化的模块名称

  17. 17

    使用grunt-contrib-connect和grunt-contrib-watch进行实时重载

  18. 18

    如何使用Javascript使用Handlebars.registerPartial

  19. 19

    如何禁用grunt-contrib-cssmin联合?

  20. 20

    如何使用Handlebars遍历JSON结构

  21. 21

    如何使用Handlebars和YUI设置onclick?

  22. 22

    带RequireJS和BackboneJS的HandleBars编译

  23. 23

    如何使用rocket_contrib Json?

  24. 24

    如何在带有Requirejs的Typescript中使用模块/类

  25. 25

    使用globlob模式时grunt-contrib-concat的奇怪行为

  26. 26

    使用grunt-contrib-connect指定标题

  27. 27

    阻止Grunt Contrib Uglify删除未使用的Javascript

  28. 28

    使用globlob模式时grunt-contrib-concat的奇怪行为

  29. 29

    无法使用grunt-contrib-cssmin创建缩小的CSS文件

热门标签

归档