Skip to content

Commit d1e594c

Browse files
lalandjoshwiens
authored andcommitted
test: Add default export test
1 parent e04e969 commit d1e594c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 5 additions & 1 deletion
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`:
@@ -215,7 +219,7 @@ will write the _.html_ file for you. Example:
215219
<td align="center">
216220
<img width="150 height="150"
217221
src="https://avatars.githubusercontent.com/u/18315?v=3">
218-
<a href="https://github.com/hemanth">Hermanth</a>
222+
<a href="https://github.com/hemanth">Hemanth</a>
219223
</td>
220224
<td align="center">
221225
<img width="150 height="150"

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)