Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ddmy/insert-webpack-plugin
对webpack打包后的文件再次插入额外内容
https://github.com/ddmy/insert-webpack-plugin
Last synced: about 1 month ago
JSON representation
对webpack打包后的文件再次插入额外内容
- Host: GitHub
- URL: https://github.com/ddmy/insert-webpack-plugin
- Owner: ddmy
- Created: 2022-02-09T08:51:59.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-30T02:02:25.000Z (over 2 years ago)
- Last Synced: 2024-10-09T14:33:10.822Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
安装
> 支持webpack4.x webpack5.x
```bash
npm i insert-webpack-plugin -D
```使用
**webpack.config.js**
```js
const InsertPlugin = require('insert-webpack-plugin')module.exports = {
plugins: [
new InsertPlugin({
type: /.*\.js/,
inner: ['/* Author xxx */\n', '/* time: 2022/2/9 */\n']
})
]
}
```**自定义插入**
```js
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