diff --git a/src/transforms/posthtml.js b/src/transforms/posthtml.js
index 44ec3a64097..b17b1525b16 100644
--- a/src/transforms/posthtml.js
+++ b/src/transforms/posthtml.js
@@ -32,7 +32,10 @@ async function getConfig(asset) {
config.plugins = await loadPlugins(config.plugins, asset.name);
if (asset.options.minify) {
- config.plugins.push(htmlnano());
+ const htmlNanoOptions = {
+ collapseWhitespace: 'conservative'
+ };
+ config.plugins.push(htmlnano(htmlNanoOptions));
}
config.skipParse = true;
diff --git a/test/html.js b/test/html.js
index d163e1d0cc8..c877ffb2570 100644
--- a/test/html.js
+++ b/test/html.js
@@ -147,4 +147,13 @@ describe('html', function() {
}
}
});
+
+ it('should conserve the spacing in the HTML tags', async function() {
+ await bundle(__dirname + '/integration/html/index.html', {
+ production: true
+ });
+
+ let html = fs.readFileSync(__dirname + '/dist/index.html', 'utf8');
+ assert(/hello<\/i> world<\/i>/.test(html));
+ });
});
diff --git a/test/integration/html/index.html b/test/integration/html/index.html
index 61d095b8329..42a009396c6 100644
--- a/test/integration/html/index.html
+++ b/test/integration/html/index.html
@@ -11,5 +11,6 @@ Hello world
Tel link
+ hello world