Skip to content

Commit 25206b3

Browse files
committed
[#PR97] updates tests and docs
1 parent 3b8abad commit 25206b3

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ require("html?interpolate=require!./file.ftl");
141141
<div>${require('./components/gallery.html')}</div>
142142
```
143143

144+
### Export format
145+
146+
By default HTML is exported with ```module.exports```, but you can use ```exportAsEs6Default``` flag to export it as ES6 default export (via ```exports.default```)
147+
144148
### Advanced options
145149

146150
If you need to pass [more advanced options](https://github.com/webpack/html-loader/pull/46), especially those which cannot be stringified, you can also define an `htmlLoader`-property on your `webpack.config.js`:

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = function(content) {
124124
} else {
125125
content = JSON.stringify(content);
126126
}
127-
127+
128128
var exportsString = config.exportAsEs6Default? "exports.default": "module.exports";
129129

130130
return exportsString + " = " + content.replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) {

test/loaderTest.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,11 @@ describe("loader", function() {
126126
'module.exports = "<a href=\\"${list.href}\\"><img src=\\"" + require("./test.jpg") + "\\" /></a>";'
127127
);
128128
});
129+
it("should export as es6 default export", function() {
130+
loader.call({
131+
query: "?exportAsEs6Default"
132+
}, '<p>Hello world!</p>').should.be.eql(
133+
'exports.default = "<p>Hello world!</p>";'
134+
);
135+
});
129136
});

0 commit comments

Comments
 (0)