This repository was archived by the owner on May 16, 2024. It is now read-only.
File tree 7 files changed +66
-16
lines changed
7 files changed +66
-16
lines changed Original file line number Diff line number Diff line change
1
+ [* ]
2
+ end_of_line = lf
3
+ insert_final_newline = true
4
+
5
+ indent_style = space
6
+ indent_size = 2
Original file line number Diff line number Diff line change @@ -24,6 +24,34 @@ template(data) // Pass object with data
24
24
< %- include templates/ child -% >
25
25
```
26
26
27
+ ## Options
28
+
29
+ Following options can be specified in query:
30
+
31
+ ` beatify ` — enable or disable uglify-js beautify of teamplate ast
32
+
33
+ ` compileDebug ` — see ejs compileDebug option
34
+
35
+ ` htmlmin ` — see [ htmlminify section] ( #htmlminify )
36
+
37
+ ## htmlminify
38
+
39
+ ``` javascript
40
+ module: {
41
+ loaders: [
42
+ {test: / \. ejs$ / , loader: ' ejs-compiled?htmlmin' } // enable here
43
+ ]
44
+ },
45
+ ' ejs-compiled-loader' : {
46
+ ' htmlmin' : true , // or enable here
47
+ ' htmlminOptions' : {
48
+ removeComments: true
49
+ }
50
+ }
51
+ ```
52
+
53
+ See [ all options reference] ( https://github.com/kangax/html-minifier#options-quick-reference )
54
+
27
55
## License
28
56
29
57
MIT (http://www.opensource.org/licenses/mit-license.php )
Original file line number Diff line number Diff line change 1
1
var ejs = require ( 'ejs' ) ,
2
2
UglifyJS = require ( 'uglify-js' ) ,
3
3
utils = require ( 'loader-utils' ) ,
4
- path = require ( 'path' ) ;
4
+ path = require ( 'path' ) ,
5
+ htmlmin = require ( 'html-minifier' ) ,
6
+ merge = require ( 'merge' ) ;
5
7
6
8
7
9
module . exports = function ( source ) {
8
10
this . cacheable && this . cacheable ( ) ;
9
- var opts = utils . parseQuery ( this . query ) ;
11
+ var opts = merge ( this . options [ 'ejs-compiled-loader' ] || { } , utils . parseQuery ( this . query ) ) ;
10
12
opts . client = true ;
11
13
12
14
// Skip compile debug for production when running with
@@ -18,6 +20,10 @@ module.exports = function (source) {
18
20
// Use filenames relative to working dir, which should be project root
19
21
opts . filename = path . relative ( process . cwd ( ) , this . resourcePath ) ;
20
22
23
+ if ( opts . htmlmin ) {
24
+ source = htmlmin . minify ( source , opts [ 'htmlminOptions' ] || { } ) ;
25
+ }
26
+
21
27
var template = ejs . compile ( source , opts ) ;
22
28
23
29
// Beautify javascript code
Original file line number Diff line number Diff line change @@ -3,8 +3,11 @@ const assert = require('assert');
3
3
var tpl = require ( "./template.ejs" ) ;
4
4
assert . equal ( tpl ( { noun : "World" } ) , 'Hello, World!' ) ;
5
5
6
+ var tpl3 = require ( "./subdir/parent.ejs" ) ;
7
+ assert . equal ( tpl3 ( { foo : "foo" } ) , "parent: child: foo\n" ) ;
8
+
9
+ var tpl4 = require ( "./htmlmin.ejs" ) ;
10
+ assert . equal ( tpl4 ( { test : 123 } ) , '123' ) ;
11
+
6
12
var tpl2 = require ( "!!../?delimiter=?!./template2.ejs" ) ;
7
13
assert . equal ( tpl2 ( { hobbies : [ "food" , "code" ] } ) . trimRight ( ) , " I like food.\n I like code." ) ;
8
-
9
- var tpl3 = require ( "./subdir/parent.ejs" ) ;
10
- assert . equal ( tpl3 ( { foo : "foo" } ) , "parent: child: foo\n\n" ) ;
Original file line number Diff line number Diff line change
1
+ <!-- test minify --> <%= test %>
Original file line number Diff line number Diff line change 1
- Hello, <%= noun%> !
1
+ Hello, <%= noun%> !
Original file line number Diff line number Diff line change 1
1
module . exports = {
2
- entry : "./app.js" ,
3
- output : {
4
- path : __dirname ,
5
- filename : "bundle.js"
6
- } ,
7
- module : {
8
- loaders : [
9
- { test : / \. e j s $ / , loader : require . resolve ( "../" ) }
10
- ]
2
+ entry : "./app.js" ,
3
+ cache : false ,
4
+ output : {
5
+ path : __dirname ,
6
+ filename : "bundle.js"
7
+ } ,
8
+ module : {
9
+ loaders : [
10
+ { test : / \. e j s $ / , loader : require . resolve ( "../" ) + "?htmlmin" }
11
+ ]
12
+ } ,
13
+ 'ejs-compiled-loader' : {
14
+ 'htmlminOptions' : {
15
+ removeComments : true
11
16
}
12
- }
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments