Skip to content

docs: improving docs for minimizing options in webpack config #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ module: {
}
```

The enabled rules for minimizing by default are the following ones:
- removeComments
- removeCommentsFromCDATA
- removeCDATASectionsFromCDATA
- collapseWhitespace
- conservativeCollapse
- removeAttributeQuotes
- useShortDoctype
- keepClosingSlash
- minifyJS
- minifyCSS
- removeScriptTypeAttributes
- removeStyleTypeAttributes

The rules can be disabled using the following options in your `webpack.conf.js`

```js
module: {
rules: [{
test: /\.html$/,
use: [ {
loader: 'html-loader',
options: {
minimize: true,
removeComments: false,
collapseWhitespace: false
}
}],
}]
}
```

### 'Root-relative' URLs

For urls that start with a `/`, the default behavior is to not translate them.
Expand Down
29 changes: 29 additions & 0 deletions test/loaderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ describe("loader", function() {
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=\" + require("./image.png") + \" />";'
);
});

it("should preserve comments and white spaces when minimizing (via webpack config property)", function() {
loader.call({
minimize: true,
options: {
htmlLoader: {
removeComments: false,
collapseWhitespace: false
}
}
}, '<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />').should.be.eql(
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=\" + require("./image.png") + \" />";'
);
});

it("should preserve comments and white spaces when minizing (via webpack config property)", function() {
loader.call({
options: {
htmlLoader: {
minimize: true,
removeComments: false,
collapseWhitespace: false
}
}
}, '<!-- comment --><h3 customAttr="">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src="image.png" />').should.be.eql(
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p> <!-- comment --> <img src=\" + require("./image.png") + \" />";'
);
});

it("should treat attributes as case sensitive", function() {
loader.call({
minimize: true,
Expand Down