Skip to content

Commit 432becb

Browse files
authored
Merge pull request #116 from dbailo1988/IMPROVING_DOCS_FOR_MINIMIZING_OPTIONS
docs: improving docs for minimizing options in webpack config
2 parents 90c7b60 + 843c76e commit 432becb

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ module: {
102102
}
103103
```
104104

105+
The enabled rules for minimizing by default are the following ones:
106+
- removeComments
107+
- removeCommentsFromCDATA
108+
- removeCDATASectionsFromCDATA
109+
- collapseWhitespace
110+
- conservativeCollapse
111+
- removeAttributeQuotes
112+
- useShortDoctype
113+
- keepClosingSlash
114+
- minifyJS
115+
- minifyCSS
116+
- removeScriptTypeAttributes
117+
- removeStyleTypeAttributes
118+
119+
The rules can be disabled using the following options in your `webpack.conf.js`
120+
121+
```js
122+
module: {
123+
rules: [{
124+
test: /\.html$/,
125+
use: [ {
126+
loader: 'html-loader',
127+
options: {
128+
minimize: true,
129+
removeComments: false,
130+
collapseWhitespace: false
131+
}
132+
}],
133+
}]
134+
}
135+
```
136+
105137
### 'Root-relative' URLs
106138

107139
For urls that start with a `/`, the default behavior is to not translate them.

test/loaderTest.js

+29
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ describe("loader", function() {
5757
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=\" + require("./image.png") + \" />";'
5858
);
5959
});
60+
61+
it("should preserve comments and white spaces when minimizing (via webpack config property)", function() {
62+
loader.call({
63+
minimize: true,
64+
options: {
65+
htmlLoader: {
66+
removeComments: false,
67+
collapseWhitespace: false
68+
}
69+
}
70+
}, '<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />').should.be.eql(
71+
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=\" + require("./image.png") + \" />";'
72+
);
73+
});
74+
75+
it("should preserve comments and white spaces when minizing (via webpack config property)", function() {
76+
loader.call({
77+
options: {
78+
htmlLoader: {
79+
minimize: true,
80+
removeComments: false,
81+
collapseWhitespace: false
82+
}
83+
}
84+
}, '<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />').should.be.eql(
85+
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=\" + require("./image.png") + \" />";'
86+
);
87+
});
88+
6089
it("should treat attributes as case sensitive", function() {
6190
loader.call({
6291
minimize: true,

0 commit comments

Comments
 (0)