Skip to content

ddmy/insert-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Insert Webpack Plugin

对webpack打包后的文件再次进行额外的操作

安装

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

协助

  • 如果您在使用中遇到了任何问题,欢迎提issues

About

对webpack打包后的文件再次插入额外内容

Resources

Stars

Watchers

Forks

Packages

No packages published