Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了gruntjs – 带汇编的生成页面的路径大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在努力使用 grunt-assemble grunt任务配置,如下所示:

assemble: {
  options: {
    flatten: false,expand: true,assets: '',layout: 'default.hbs',layoutdir: 'templates/layouts',partials: ['templates/includes/*.hbs'],Helpers: ['templates/Helpers/*.js'],data: ['templates/data/*.{json,yml}']
  },dev: {
    src: 'templates/pages/**/*.hbs',dest: 'build/'
  }

assemble.io的项目模板的脚手架如下所示:

templates
├── Helpers
├── includes
│   ├── page-footer.hbs
│   ├── page-header.hbs
│   └── scripts.hbs
├── layouts
│   └── default.hbs
└── pages
    ├── en
    │   └── index.hbs
    ├── fr
    │   └── index.hbs
    └── index.hbs

我希望得到类似的东西:

build
├── en
│   └── index.html
├── fr
│   └── index.html
└── index.html

但相反,我得到类似的东西:

build
└── templates
    └── pages
        ├── en
        │   └── index.html
        ├── fr
        │   └── index.html
        └── index.html

我确实尝试了一些(实际上很多)组合(平坦和扩展以及cwd选项)但我被卡住了.

因此,使用flatten会使index.html文件相互覆盖.

所以我实际上将渲染转换为.tmp目录,然后将文件移动到构建目录.
我不喜欢那个解决方案,因为那时,page.assets仍然被破坏(对于root index.html,它的值为.. / .. / ..).

解决方法

咕噜组装

(请注意,此信息特指grunt-assemble 0.4.x,这是用于汇编的grunt插件,但具有完全不同的API)

@doowb几乎是正确的,尝试将expand:true和ext:’.html’添加文件配置中:

assemble: {
  options: {
    flatten: false,dev: {
    files: [
      {expand: true,cwd: 'templates/pages/',src: '**/*.hbs',dest: 'build/',ext: '.html'}
    ]
  }
}

另外看看https://github.com/assemble/assemble-contrib-permalinks

装配0.7.x.

集合是0.7.0中的一流集合,插件也是如此,因此生成相对链接,构建分页和创建自定义永久链接内容要容易得多.

如果你正在使用assembly 0.7.x及更高版本,那么assemble-permalinks就是你想要使用的插件.

大佬总结

以上是大佬教程为你收集整理的gruntjs – 带汇编的生成页面的路径全部内容,希望文章能够帮你解决gruntjs – 带汇编的生成页面的路径所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。