html-webpack-auto-inject-plugin,auto inject js file to html
Sometimes,I just need require/import a js source inject to html file.ie:flexible.js
,some log js
,but I have to modify html template file or require/import file that I won't actually exec by code manually.
Now Support:
- Auto inject js file
- Compress js file
Will Support
- Auto inject css file
- Do you want by create issue to me
This plugin require html-webpack-plugin
,because listen the event by emit html-webpack-plugin
:html-webpack-plugin-before-html-processing
.
You must be running webpack on node 4 or higher
Install the plugin with npm:
$ npm install --save-dev html-webpack-auto-inject-plugin
# for npm > 5
$ npm install --only=dev html-webpack-auto-inject-plugin
Require the plugin in your webpack config:
const HtmlWebpackAutoInjectPlugin = require('html-webpack-auto-inject-plugin');
Add the plugin to your webpack config as follows:
For now,just support javascript file import,will support css file import in 1.0 version.
All javascript file import config are set in script
- script [Array] : Accept
string
for file path andObject
for custom config. String:for javascript path.relative
orabsolute
. Object:- path: Like directly set string above config
- compress [Boolean]: compress or not.Use
uglify-js
.
plugins: [
new HtmlWebpackPlugin(),
new HtmlWebpackAutoInjectPlugin({
script: [
// relative path
'./path/to/js',
// absolute path
'/User/sinoon/code/path/to/js',
// custom config
{
path: './path/to/js',
compress: true
}
]
})
]