项目作者: yohangz

项目描述 :
Handlebars template bundle rollup plugin
高级语言: JavaScript
项目地址: git://github.com/yohangz/rollup-plugin-hbs.git
创建时间: 2018-06-29T12:50:52Z
项目社区:https://github.com/yohangz/rollup-plugin-hbs

开源协议:MIT License

下载



travis build


license


npm version

rollup-plugin-hbs

Minimal handlebars template bundle rollup plugin based on rollup-plugin-handlebars-plus

Installation

Via Yarn

yarn add rollup-plugin-hbs --save-dev

Via NPM

npm install rollup-plugin-hbs --save-dev

Usage

Rollup Configuration

  1. // rollup.config.js
  2. import hbs from 'rollup-plugin-hbs';
  3. export default {
  4. entry: 'entry.js',
  5. dest: 'bundle.js',
  6. plugins: [
  7. hbs({
  8. handlebars: {
  9. // The module ID of the Handlebars runtime, exporting `Handlebars` as `default`.
  10. // As a shortcut, you can pass this as the value of `handlebars` above.
  11. // See the "Handlebars" section below.
  12. id: 'handlebars', // Default: the path of Handlebars' CJS definition within this module
  13. // Options to pass to Handlebars' `parse` and `precompile` methods.
  14. options: {
  15. // Whether to generate sourcemaps for the templates
  16. sourceMap: true // Default: true
  17. },
  18. // Whether to remove newline and whitespace characters from compiled output.
  19. optimize: true
  20. },
  21. // In case you want to compile files with other extensions.
  22. templateExtension: '.html', // Default: '.hbs'
  23. // A function that can determine whether or not a template is a partial.
  24. isPartial: (name) => name.startsWith('_') // Default: as at left
  25. })
  26. ]
  27. }

Usage in code

  1. {{! src/client/js/views/_messageBody.html }}
  2. <p>{{message}}</p>
  1. {{! src/client/js/views/message.html }}
  2. <div>{{> _messageBody }}</div>
  1. // main.js
  2. import '_messageBody.html';
  3. import MessageTemplate from 'message.html';
  4. $('body').append(MessageTemplate({ message: 'Hello world!' }));

License

This software is licensed under the MIT License