Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit d6a573f

Browse files
committed
chore: update readme
1 parent 9824c1d commit d6a573f

1 file changed

Lines changed: 58 additions & 1 deletion

File tree

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,63 @@
11
# karma-html2js-preprocessor [![Build Status](https://travis-ci.org/karma-runner/karma-html2js-preprocessor.png?branch=master)](https://travis-ci.org/karma-runner/karma-html2js-preprocessor)
22

3-
> Preprocessor for converting HTML files to JS strings.
3+
> Preprocessor for converting HTML files into JS strings.
4+
5+
*Note:* If you are using [AngularJS](http://angularjs.org/), check out [karma-ng-html2js-preprocessor](https://github.com/karma-runner/karma-ng-html2js-preprocessor).
6+
7+
## Installation
8+
9+
**This plugin ships with Karma by default, so you don't need to install it, it should just work ;-)**
10+
11+
The easiest way is to keep `karma-html2js-preprocessor` as a devDependency in your `package.json`.
12+
```json
13+
{
14+
"devDependencies": {
15+
"karma": "~0.9",
16+
"karma-html2js-preprocessor": "~0.0.1"
17+
}
18+
}
19+
```
20+
21+
You can simple do it by:
22+
```bash
23+
npm install karma-html2js-preprocessor --save-dev
24+
```
25+
26+
## Configuration
27+
Following code shows the default configuration...
28+
```js
29+
// karma.conf.js
30+
module.exports = function(config) {
31+
config.set({
32+
preprocessors: {
33+
'**/*.html': ['html2js']
34+
},
35+
36+
files: [
37+
'*.js',
38+
'*.html'
39+
]
40+
});
41+
};
42+
```
43+
44+
## How does it work ?
45+
46+
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.
47+
48+
For instance this `template.html`...
49+
```html
50+
<div>something</div>
51+
```
52+
... will be served as `template.html.js`:
53+
```js
54+
window.__html__ = window.__html__ || {};
55+
window.__html__['template.html'] = '<div>something</div>';
56+
```
57+
58+
See the [end2end test](https://github.com/karma-runner/karma/tree/master/test/e2e/html2js) for a complete example.
59+
60+
----
461

562
For more information on Karma see the [homepage].
663

0 commit comments

Comments
 (0)