question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to avoid closing body and html tags in output file?

See original GitHub issue

Hello! Is it possible to exclude closing body and html tags from the output file? The plugin puts these tags automatically, but I want to avoid this. My template looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>My template</title>
</head>
<body>
    <!-- some code -->

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
yisenliucommented, Dec 29, 2019

@Sigizmund2012 try to modify index.js like this:

const path = require('path');
const critical = require('critical');

class HtmlCriticalWebpackPlugin {

  constructor(options,callback) {
    this.options = options;
    this.userCallback =  callback;
  }

  emit(compilation, callback) {
    const css = Object.keys(compilation.assets)
      .filter(function (filename) { return /\.css$/.test(filename); })
      .map(function (filename) { return path.join(compilation.outputOptions.path, filename); });

    critical.generate(Object.assign({ css }, this.options), (err,html) => {
      callback(err);
      this.userCallback(html);
    });
  }

  apply(compiler) {
    compiler.hooks.afterEmit.tapAsync('HtmlCriticalWebpackPlugin', (compilation, callback) => {
      this.emit(compilation, callback);
    });
  }

}

module.exports = HtmlCriticalWebpackPlugin;

and your webpack.config.js:

new HtmlCriticalWebpackPlugin({...},function(html){
    console.log(html); // your statements
})
1reaction
Sigizmund2012commented, Dec 5, 2019

But in the critical module there is an opportunity to get the HTML source code and modify it. There is no such possibility in html-critical-webpack-plugin.

critical.generate({
    base: 'test/',
    src: 'index.html',
    width: 1300,
    height: 900,
    inline: true
}, (err, ({css, html, uncritical})) => {
    // You now have critical-path CSS as well as the modified HTML.
    // Works with and without target specified.
    ...
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can you leave out closing tags in HTML for tags that extend ...
1 Answer 1 ... You should ALWAYS close your tags. Most browsers are "forgiving" ... but that doesn't make it "right". You should...
Read more >
HTML tags should not be automatically closed in template ...
The problem is that it's trying too hard to close that <head> tag, but in HTML both the opening <head> tag and closing...
Read more >
WebD2: Common HTML Tags - University of Washington
Examples are images and line breaks. XHTML is more strict than HTML, and requires that all open tags must be closed, even if...
Read more >
What are Self Closing Tags in HTML? - Scaler Topics
This article by Scaler Topics will cover what self-closing tags in HTML along with their syntax, attribute values, and examples.
Read more >
The Document Body element - HTML - MDN Web Docs - Mozilla
The start tag may be omitted if the first thing inside it is not a space character, comment, <script> element or <style> element....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found