File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -141,9 +141,13 @@ require("html?interpolate=require!./file.ftl");
141
141
<div >${require('./components/gallery.html')}</div >
142
142
```
143
143
144
- ### Export format
144
+ ### Export formats
145
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 ``` )
146
+ There are different export formats available:
147
+
148
+ + ``` module.exports ``` (default, cjs format). "Hello world" becomes ``` module.exports = "Hello world"; ```
149
+ + ``` exports.default ``` (when ``` exportAsDefault ``` param is set, es6to5 format). "Hello world" becomes ``` exports.default = "Hello world"; ```
150
+ + ``` exports default ``` (when ``` exportAsEs6Default ``` param is set, es6 format). "Hello world" becomes ``` exports default "Hello world"; ```
147
151
148
152
### Advanced options
149
153
Original file line number Diff line number Diff line change @@ -125,9 +125,15 @@ module.exports = function(content) {
125
125
content = JSON . stringify ( content ) ;
126
126
}
127
127
128
- var exportsString = config . exportAsEs6Default ? "exports.default" : "module.exports" ;
129
-
130
- return exportsString + " = " + content . replace ( / x x x H T M L L I N K x x x [ 0 - 9 \. ] + x x x / g, function ( match ) {
128
+ var exportsString = "module.exports = " ;
129
+ if ( config . exportAsDefault ) {
130
+ exportsString = "exports.default = " ;
131
+
132
+ } else if ( config . exportAsEs6Default ) {
133
+ exportsString = "exports default " ;
134
+ }
135
+
136
+ return exportsString + content . replace ( / x x x H T M L L I N K x x x [ 0 - 9 \. ] + x x x / g, function ( match ) {
131
137
if ( ! data [ match ] ) return match ;
132
138
return '" + require(' + JSON . stringify ( loaderUtils . urlToRequest ( data [ match ] , root ) ) + ') + "' ;
133
139
} ) + ";" ;
Original file line number Diff line number Diff line change @@ -126,11 +126,18 @@ describe("loader", function() {
126
126
'module.exports = "<a href=\\"${list.href}\\"><img src=\\"" + require("./test.jpg") + "\\" /></a>";'
127
127
) ;
128
128
} ) ;
129
+ it ( "should export as default export for es6to5 transpilation" , function ( ) {
130
+ loader . call ( {
131
+ query : "?exportAsDefault"
132
+ } , '<p>Hello world!</p>' ) . should . be . eql (
133
+ 'exports.default = "<p>Hello world!</p>";'
134
+ ) ;
135
+ } ) ;
129
136
it ( "should export as es6 default export" , function ( ) {
130
137
loader . call ( {
131
138
query : "?exportAsEs6Default"
132
139
} , '<p>Hello world!</p>' ) . should . be . eql (
133
- 'exports.default = "<p>Hello world!</p>";'
140
+ 'exports default "<p>Hello world!</p>";'
134
141
) ;
135
142
} ) ;
136
143
} ) ;
You can’t perform that action at this time.
0 commit comments