Skip to content

Commit 06c9ba4

Browse files
committed
updates README.md
1 parent 84e9d9e commit 06c9ba4

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,64 @@ var Handlebars = require('handlebars');
122122
var templates = require('./templates')(Handlebars);
123123
```
124124

125+
126+
#### es2015
127+
Type: `Boolean` or `Array`
128+
Default: `false`
129+
130+
Formats the output file as an ES2015 module, exports the result both as a named export as well as a default export.
131+
132+
For this option to work the `namespace` property needs to be defined.
133+
If not defined or explicitly set to `false`, the task's `namespace` property will instead default to `JST`.
134+
135+
136+
If `Array` then each array entry is expected to have both a variable and path properties:
137+
138+
```js
139+
es2015: [
140+
{variable: '$', path: 'jquery'},
141+
{variable: 'Handlebars', path: 'handlebars.runtime.js'},
142+
{variable: '{NamedModule}', path: 'my_module.js'}
143+
]
144+
```
145+
146+
Each of these will, in turn, be imported at the top of the compilation file:
147+
148+
149+
```js
150+
import $ from 'jquery';
151+
import Handlebars from 'handlebars.runtime.js';
152+
import {NamedModule} from 'my_module.js';
153+
```
154+
155+
If the es2015 property is a string, a function or `true` these imports will default to:
156+
157+
```js
158+
import Handlebars from 'handlebars.runtime.js';
159+
```
160+
161+
As you might know, you can't use `this` inside an es2015 module to reference the global scope. It's undefined as per specification.
162+
Instead of `this`, you can pass a `root` option to be used in its place.
163+
164+
```js
165+
options: {
166+
root: 'templates'
167+
}
168+
```
169+
170+
If said option isn't declared, the task's `root` property will default to `templates`
171+
172+
So, for example, if you use the default namespace `JST`, the compiled file will end with:
173+
174+
```js
175+
var JST = templates["JST"];
176+
export {JST};
177+
export default JST;
178+
```
179+
180+
The `root` option (albeit is not needed except for es2015 format) can be safely used with all output formats.
181+
182+
125183
#### processContent
126184
Type: `Function`
127185

0 commit comments

Comments
 (0)