-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
5,683 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"target": { | ||
"node": 4 | ||
} | ||
} | ||
], | ||
"stage-0" | ||
], | ||
"plugins": [ | ||
"add-module-exports" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"ignore": [ | ||
"**/node_modules/**", | ||
"**/lib/**", | ||
"**/es/**", | ||
"**/dist/**" | ||
], | ||
"test": [ | ||
"**/test/**" | ||
], | ||
"critics": { | ||
"lint": {"engine": "eslint"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# http://editorconfig.org | ||
|
||
# A special property that should be specified at the top of the file outside of | ||
# any sections. Set to true to stop .editor config file search on current file | ||
root = true | ||
|
||
[*] | ||
# Indentation style | ||
# Possible values - tab, space | ||
indent_style = space | ||
|
||
# Indentation size in single-spaced characters | ||
# Possible values - an integer, tab | ||
indent_size = 2 | ||
|
||
# Line ending file format | ||
# Possible values - lf, crlf, cr | ||
end_of_line = lf | ||
|
||
# File character encoding | ||
# Possible values - latin1, utf-8, utf-16be, utf-16le | ||
charset = utf-8 | ||
|
||
# Denotes whether to trim whitespace at the end of lines | ||
# Possible values - true, false | ||
trim_trailing_whitespace = true | ||
|
||
# Denotes whether file should end with a newline | ||
# Possible values - true, false | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
|
||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "standard", | ||
"parser": "babel-eslint" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- 4.0.0 | ||
- 5.0.0 | ||
- 6.0.0 | ||
- 8.9.1 | ||
- 9.2.0 | ||
|
||
install: | ||
- npm install | ||
|
||
script: | ||
- npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,50 @@ | ||
# html-webpack-inject-plugin | ||
inject external source to html | ||
|
||
inject external tag to html | ||
|
||
## Installation | ||
|
||
You must be running webpack on node 4.x or higher | ||
|
||
```bash | ||
npm install --save-dev html-webpack-inject-plugin | ||
``` | ||
|
||
## Usage | ||
|
||
Require the plugin in your webpack config | ||
|
||
```javascript | ||
import HtmlWebpackInjectPlugin from 'html-webpack-inject-plugin' | ||
// or | ||
var HtmlWebpackInjectPlugin = require('html-webpack-inject-plugin') | ||
``` | ||
|
||
Add the plugin to your webpack config as follows | ||
|
||
```javascript | ||
plugins: [ | ||
new HtmlWebpackPlugin(), | ||
new HtmlWebpackIncludeAssetsPlugin({ | ||
externals: [{ | ||
tag: 'script', | ||
attrs: { | ||
src: 'your-script.js', | ||
type: 'text/javascript' | ||
} | ||
}], | ||
parent: 'head' // default is head | ||
}) | ||
] | ||
``` | ||
|
||
## Options | ||
|
||
- `externals: Array<Tag>`: external [tags](#Tag) which you want to add | ||
|
||
- `parent`: parent element will be added into, only can be `head` and `body`, default value is `head` | ||
|
||
## Tag | ||
|
||
- `tag`: tag name, such as `meta` `link` `script` | ||
- `attrs`: [html attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
var HtmlWebpackInjectPlugin = function HtmlWebpackInjectPlugin(config) { | ||
var _this = this; | ||
|
||
_classCallCheck(this, HtmlWebpackInjectPlugin); | ||
|
||
this.apply = function (compiler) { | ||
compiler.plugin('compilation', function (compilation) { | ||
compilation.plugin('html-webpack-plugin-alter-asset-tags', function (htmlPluginData, cb) { | ||
if (_this.parent === 'head') { | ||
htmlPluginData.head = htmlPluginData.head.concat(_this.assets); | ||
} else { | ||
htmlPluginData.body = _this.assets.concat(htmlPluginData.body); | ||
} | ||
return cb(null, htmlPluginData); | ||
}); | ||
}); | ||
}; | ||
|
||
var _config$externals = config.externals, | ||
externals = _config$externals === undefined ? [] : _config$externals, | ||
_config$parent = config.parent, | ||
parent = _config$parent === undefined ? 'head' : _config$parent; | ||
|
||
|
||
this.assets = externals.map(function (_ref) { | ||
var _ref$tag = _ref.tag, | ||
tag = _ref$tag === undefined ? 'meta' : _ref$tag, | ||
_ref$attrs = _ref.attrs, | ||
attrs = _ref$attrs === undefined ? {} : _ref$attrs; | ||
|
||
return { | ||
tagName: tag, | ||
attributes: attrs, | ||
closeTag: true | ||
}; | ||
}); | ||
|
||
if (parent !== 'head' && parent !== 'body') { | ||
throw new TypeError('parent should be one of head and body'); | ||
} | ||
this.parent = parent; | ||
}; | ||
|
||
exports.default = HtmlWebpackInjectPlugin; | ||
module.exports = exports['default']; |
Oops, something went wrong.