Skip to content

Commit cc116a9

Browse files
[squash] refactor(index): use htmlnano instead of html-minifier (options.minimize)
1 parent 9d9db02 commit cc116a9

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dist"
1313
],
1414
"dependencies": {
15+
"htmlnano": "^0.1.6",
1516
"loader-utils": "^1.0.0",
1617
"posthtml": "^0.10.0",
1718
"schema-utils": "0.3.0"

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import validateOptions from 'schema-utils';
55
import posthtml from 'posthtml';
66
import urls from './lib/plugins/url';
77
import imports from './lib/plugins/import';
8+
import minifier from 'htmlnano';
89

910
import schema from './options.json';
1011
import LoaderError from './lib/Error';
@@ -30,6 +31,7 @@ export default function loader(html) {
3031

3132
if (options.url) plugins.push(urls());
3233
if (options.import) plugins.push(imports());
34+
if (options.minimize) plugins.push(minifier());
3335

3436
posthtml(plugins).process(html, { from: file, to: file })
3537
.then((result) => {

src/options.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
},
1010
"template": {
1111
"type": [ "boolean", "string" ]
12+
},
13+
"minimize": {
14+
"type": [ "boolean", "object" ]
1215
}
1316
},
1417
"additionalProperties": false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Options minimize {Boolean} 1`] = `
4+
"// HTML Imports
5+
6+
7+
8+
// HTML Content
9+
export default \`<!DOCTYPE html><html lang=\\"en\\"><head><meta charset=\\"utf-8\\"><title>HTML Loader</title></head><body><div id=\\"app\\"></div></body></html>\`"
10+
`;

test/options/minimize.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-disable
2+
prefer-destructuring,
3+
*/
4+
import webpack from '../helpers/compiler';
5+
6+
describe('Options', () => {
7+
describe('minimize', () => {
8+
test('{Boolean}', async () => {
9+
const config = {
10+
loader: {
11+
test: /\.html$/,
12+
options: {
13+
minimize: true,
14+
},
15+
},
16+
};
17+
18+
const stats = await webpack('fixture.js', config);
19+
const { source } = stats.toJson().modules[1];
20+
21+
expect(source).toMatchSnapshot();
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)