转载自 Coding.Art
webpack1+
install
npm install injectjscss-template-html-webpack-plugin
or
yarn add injectjscss-template-html-webpack-plugin
use
const injectJsCssTemplateHtmlWebpackPlugin = require('injectjscss-template-html-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin');
/* webpack config add */
plugin: [
new htmlWebpackPlugin({....}),
new injectJsCssTemplateHtmlWebpackPlugin(options), // 这个必须写在html-webpack-plugin 后面
....
]
options
Object or Array
-
injectTemplateId - number
当有多个html-wepack-plugin的时候, 插件将通过injectTemplateId来匹配 对应的设置
同时html-webpack-plugin需要添加相同的injectTemplateId
example:
plugin: [
new htmlWebpackPlugin({
injectTemplateId: 0,
....
}),
new htmlWebpackPlugin({
injectTemplateId: 1,
....
}),
new injectJsCssTemplateHtmlWebpackPlugin([{
injectTemplateId: 0,
...
},{
injectTemplateId: 1,
...
}])
]
- jstemplate - function
function(everypath){
.....
return path;
}
- csstemplate - function
function(everypath){
.....
return path;
}