Coder Social home page Coder Social logo

html-webpack-inline-code-plugin's Introduction

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>

html-webpack-inline-code-plugin's People

Contributors

cklwblove avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.