4.0.3 • Published 2 years ago

insert-webpack-plugin v4.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

 支持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
innerArray[]要插入文件头部的内容(目前仅支持在头部插入)
  • 不同文件插入不同内容
  • webpack5支持