File tree Expand file tree Collapse file tree
integration/htmlnano-config Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,10 +32,12 @@ async function getConfig(asset) {
3232 config . plugins = await loadPlugins ( config . plugins , asset . name ) ;
3333
3434 if ( asset . options . minify ) {
35- const htmlNanoOptions = {
36- collapseWhitespace : 'conservative'
37- } ;
38- config . plugins . push ( htmlnano ( htmlNanoOptions ) ) ;
35+ const htmlNanoConfig = asset . package . htmlnano ||
36+ ( await Config . load ( asset . name , [ '.htmlnanorc' , '.htmlnanorc.js' ] ) ) || {
37+ collapseWhitespace : 'conservative'
38+ } ;
39+
40+ config . plugins . push ( htmlnano ( htmlNanoConfig ) ) ;
3941 }
4042
4143 config . skipParse = true ;
Original file line number Diff line number Diff line change @@ -124,9 +124,36 @@ describe('html', function() {
124124 production : true
125125 } ) ;
126126
127- let css = fs . readFileSync ( __dirname + '/dist/index.html' , 'utf8' ) ;
128- assert ( css . includes ( 'Other page' ) ) ;
129- assert ( ! css . includes ( '\n' ) ) ;
127+ let html = fs . readFileSync ( __dirname + '/dist/index.html' , 'utf8' ) ;
128+ assert ( html . includes ( 'Other page' ) ) ;
129+ assert ( ! html . includes ( '\n' ) ) ;
130+ } ) ;
131+
132+ it ( 'should read .htmlnanorc and minify HTML in production mode' , async function ( ) {
133+ await bundle ( __dirname + '/integration/htmlnano-config/index.html' , {
134+ production : true
135+ } ) ;
136+
137+ let html = fs . readFileSync ( __dirname + '/dist/index.html' , 'utf8' ) ;
138+
139+ // mergeStyles
140+ assert (
141+ html . includes (
142+ '<style>h1{color:red}div{font-size:20px}</style><style media="print">div{color:blue}</style>'
143+ )
144+ ) ;
145+
146+ // minifyJson
147+ assert (
148+ html . includes ( '<script type="application/json">{"user":"me"}</script>' )
149+ ) ;
150+
151+ // minifySvg is false
152+ assert (
153+ html . includes (
154+ '<svg version="1.1" baseprofile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="red"></rect><circle cx="150" cy="100" r="80" fill="green"></circle><text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text></svg>'
155+ )
156+ ) ;
130157 } ) ;
131158
132159 it ( 'should not prepend the public path to assets with remote URLs' , async function ( ) {
Original file line number Diff line number Diff line change 1+ {
2+ mergeStyles: true,
3+ minifySvg: false,
4+ minifyJson: true
5+ }
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < title > Test</ title >
5+ < style > h1 { color : red }</ style >
6+ < style media ="print "> div { color : blue }</ style >
7+
8+ < style type ="text/css " media ="print "> a {}</ style >
9+ < style > div { font-size : 20px }</ style >
10+ </ head >
11+ < body >
12+ < h1 > Index page</ h1 >
13+ < svg version ="1.1 " baseProfile ="full " width ="300 " height ="200 " xmlns ="http://www.w3.org/2000/svg ">
14+ < rect width ="100% " height ="100% " fill ="red " />
15+
16+ < circle cx ="150 " cy ="100 " r ="80 " fill ="green " />
17+
18+ < text x ="150 " y ="125 " font-size ="60 " text-anchor ="middle " fill ="white "> SVG</ text >
19+ </ svg >
20+ < script type ="application/json ">
21+ {
22+ "user" : "me"
23+ }
24+ </ script >
25+
26+ </ body >
27+ </ html >
You can’t perform that action at this time.
0 commit comments