grunt-html2amd

A task to convert HTML templates to AMD javascript

Usage no npm install needed!

<script type="module">
  import gruntHtml2amd from 'https://cdn.skypack.dev/grunt-html2amd';
</script>

README

grunt-html2amd

A task to convert HTML templates to AMD javascript

Sample:

** main.html **

<div><p id="Para1">Paragraph</p></div>

Output -> ** main.html.js **

define(function(){ return '<div><p id="Para1">Paragraph</p></div>' });

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-html2amd --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-html2amd');

The "html2amd" task

Overview

In your project's Gruntfile, add a section named html2amd to the data object passed into grunt.initConfig().

grunt.initConfig({
  html2amd: {
    your_target: {
      src:// wild card or array of html files
    },
  },
});

Usage Examples

grunt.initConfig({
  html2amd: {
    dist: {
      src: ["pages/*/*.html","templates/*.html"]
    }
  }
});

The plugin would output a separate ** .js ** file for each html input file ( appending .js extention to the original name ).

For example: ** pages/main/main.html ** would output: ** pages/main/main.html.js **