Skip to content

cklwblove/html-webpack-inline-code-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inline Code tag for the HTML Webpack Plugin

npm version Build status js-semistandard-style

This is an extension plugin for the webpack plugin html-webpack-plugin (version 3.x or 4 or higher). It allows you to embed javascript and css source inline.

Installation

You must be running webpack on node 6 or higher.

Install the plugin with npm:

$ npm install --save-dev html-webpack-inline-code-plugin

Basic Usage

Require the plugin in your webpack config:

var HtmlWebpackInlineCodePlugin = require('html-webpack-inline-code-plugin');

Add the plugin to your webpack config as follows:

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackInlineCodePlugin()
]  

The above configuration will actually do nothing due to the configuration defaults.

Options

The available options are:

  • headTags | bodyTags: array
    • tagsName: string, Specifies the code extensions to use to determine. One of the script or style values;
    • tagsCode: string Inserted specific code.

Example

config code

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackInlineSourcePlugin({
    headTags: [{
      tagName: 'script',
      tagCode: `var startTime = +new Date();`
    }],
    bodyTags: [{
      tagName: 'script',
      tagCode: `var endTime = +new Date();`
    }]
  })
]  

Source html code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Example</title>
  </head>
  <body>
    <noscript>
      <strong>很抱歉,如果没有启用JavaScript,此项目将无法正常运行。请启用它。</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

Build compiled code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Example</title>
    <script type="text/javascript">var startTime = +new Date();</script>
  </head>
  <body>
    <noscript>
      <strong>很抱歉,如果没有启用JavaScript,此项目将无法正常运行。请启用它。</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
    <script type="text/javascript">var endTime = +new Date();</script>
  </body>
</html>

About

Inline Code extension for the HTML Webpack Plugin

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors