An open API service indexing awesome lists of open source software.

https://github.com/cklwblove/html-webpack-inline-code-plugin

Inline Code extension for the HTML Webpack Plugin
https://github.com/cklwblove/html-webpack-inline-code-plugin

html-webpack html-webpack-html-plugin

Last synced: 4 months ago
JSON representation

Inline Code extension for the HTML Webpack Plugin

Awesome Lists containing this project

README

          

Inline Code tag for the HTML Webpack Plugin
===========================================
[![npm version](https://badge.fury.io/js/html-webpack-inline-code-plugin.svg)](https://badge.fury.io/js/html-webpack-inline-code-plugin) [![Build status](https://travis-ci.org/cklwblove/html-webpack-inline-code-plugin.svg?branch=master)](https://travis-ci.org/cklwblove/html-webpack-inline-code-plugin) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard)

This is an extension plugin for the [webpack](http://webpack.github.io) plugin [html-webpack-plugin](https://github.com/ampedandwired/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:
```shell
$ npm install --save-dev html-webpack-inline-code-plugin
```

Basic Usage
-----------
Require the plugin in your webpack config:

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

Add the plugin to your webpack config as follows:

```javascript
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
```javascript
plugins: [
new HtmlWebpackPlugin(),
new HtmlWebpackInlineSourcePlugin({
headTags: [{
tagName: 'script',
tagCode: `var startTime = +new Date();`
}],
bodyTags: [{
tagName: 'script',
tagCode: `var endTime = +new Date();`
}]
})
]
```

Source html code
```html





Example



很抱歉,如果没有启用JavaScript,此项目将无法正常运行。请启用它。



```

Build compiled code
```html





Example
var startTime = +new Date();



很抱歉,如果没有启用JavaScript,此项目将无法正常运行。请启用它。



var endTime = +new Date();

```