Socket
Socket
Sign inDemoInstall

karma-html2js-preprocessor

Package Overview
Dependencies
137
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    karma-html2js-preprocessor

A Karma plugin. Convert HTML files into JS strings to serve them in a script tag.


Version published
Weekly downloads
34K
decreased by-6.83%
Maintainers
3
Install size
6.59 kB
Created
Weekly downloads
 

Readme

Source

karma-html2js-preprocessor Build Status

Preprocessor for converting HTML files into JS strings.

Note: If you are using AngularJS, check out karma-ng-html2js-preprocessor.

Installation

The easiest way is to keep karma-html2js-preprocessor as a devDependency in your package.json.

{
  "devDependencies": {
    "karma": "~0.10",
    "karma-html2js-preprocessor": "~0.1"
  }
}

You can simple do it by:

npm install karma-html2js-preprocessor --save-dev

Configuration

// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      '**/*.html': ['html2js']
    },

    files: [
      '*.js',
      '*.html'
    ],

    html2JsPreprocessor: {
      // strip this from the file path
      stripPrefix: 'public/',

      // prepend this to the file path
      prependPrefix: 'served/',

      // or define a custom transform function
      processPath: function(filePath) {
        // Drop the file extension
        return filePath.replace(/\.html$/, '');
      }
    }
  });
};

How does it work ?

This preprocessor converts HTML files into JS strings and publishes them in the global window.__html__, so that you can use these for testing DOM operations.

For instance this template.html...

<div>something</div>

... will be served as template.html.js:

window.__html__ = window.__html__ || {};
window.__html__['template.html'] = '<div>something</div>';

See the end2end test for a complete example.


For more information on Karma see the homepage.

Keywords

FAQs

Last updated on 21 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc