auto-inject-webpack
this is a Webpack plugin that can auto inject script label and style links into your html, useful in multi-entry project.
usage
install this plugin via npm:
npm install auto-inject-webpack-plugin -D
in your webpack.config.js:
var path = ;var webpack = ;var autoInjectPlugin = ;var commonsChunkPlugin = webpackoptimizeCommonsChunkPlugin; module { return entry: "bundle": path output: path: path filename: '[name].min.js' module: loders: ... plugins: // if you are not using commonChunks, leave this empty. name: 'commons' chunks: optionsentries minChunks: optionsentrieslength outputURI: '/dist/' commonChunks: 'commons' // name of commonsChunk. ... }
in your entry file (/res/index.js as above):
/* %/view/index.html% */// your code...
in your html file (/view/index.html):
Document <!-- css-begin --> <!-- css-end --> <!-- js-begin --> <!-- js-end -->
final html:
Document <!-- css-begin --> <!-- css-end --> <!-- js-begin --><!-- js-end -->
options
-
outputURI
: server URI of your webpack output folder.- default:
"/static/build/"
.
- default:
-
htmlPlaceholder
: RegExp to match your html path (relative path from package.json) which is designated in your entry file.- default:
/\/\*\s*\%(.+)+\%\s*\*\//
which represents/* %/path/of/your/htmlfile.html% */
.
- default:
-
jsPlaceholderBegin
: begin anchor to decide where to inject your script labels. (this anchor is designated in your html file)- default:
"<!-- js-begin -->"
- default:
-
jsPlaceholderEnd
: end anchor to decide where to inject your script labels. (this anchor is designated in your html file)- default:
"<!-- js-end -->"
- default:
-
cssPlaceholderBegin
: begin anchor to decide where to inject your style link labels. (this anchor is designated in your html file)- default:
"<!-- css-begin -->"
- default:
-
cssPlaceholderBegin
: end anchor to decide where to inject your style link labels. (this anchor is designated in your html file)- default:
"<!-- css-end -->"
- default: