insert-webpack-plugin
v4.0.3
Published
webpack打包文件插入内容
Downloads
4
Readme
支持webpack4.x webpack5.x
npm i insert-webpack-plugin -D
webpack.config.js
const InsertPlugin = require('insert-webpack-plugin')
module.exports = {
plugins: [
new InsertPlugin({
type: /.*\.js/,
inner: ['/* Author xxx */\n', '/* time: 2022/2/9 */\n']
})
]
}
自定义插入
module.exports = {
plugins: [
new InsertPlugin({
type: /.*\.js/,
insertPosition: source => {
return source.slice(0, 50) + '\n /* Hello World */ \n' + source.slice(51)
}
})
]
}
|参数名|类型|默认值|描述|
|:--:|:--:|:-----:|:----------|
type
|{String|RegExp}| /.*/ |要处理的文件范围
insertPosition
|{String|Function}|'before'|要插入的位置 String: 'before'|'after'Function 接收文件source参数,值为文件内容String,使用此方式,方法必须返回处理后的String,使用Function将会忽略inner
inner
|Array|[]|要插入文件头部的内容(目前仅支持在头部插入)
- 不同文件插入不同内容
- webpack5支持