# extra-code-webpack-plugin

> 添加额外的代码的 webpack 插件 | add extra code plugin for webpack

Latest version **1.0.2** (published 2021-07-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install extra-code-webpack-plugin
pnpm add extra-code-webpack-plugin
yarn add extra-code-webpack-plugin
bun add extra-code-webpack-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-07-15 |
| First published | 2021-07-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | postor |

## Links

- npm: https://www.npmjs.com/package/extra-code-webpack-plugin
- Repository: https://github.com/postor/extra-code-webpack-plugin
- Homepage: https://github.com/postor/extra-code-webpack-plugin#readme
- Issues: https://github.com/postor/extra-code-webpack-plugin/issues
- npm.io page: https://npm.io/package/extra-code-webpack-plugin

## Dependencies (1)

- [loader-utils](https://npm.io/package/loader-utils.md) ^2.0.0

## Recent versions

- 1.0.2 (latest) — 2021-07-15
- 1.0.1 — 2021-07-15
- 1.0.0 — 2021-07-15

## README

# extra-code-webpack-plugin

添加额外的代码的 webpack 插件 | add extra code plugin for webpack

## usage

install

```
npm i extra-code-webpack-plugin -D
```

webpack.config.js

```
const ExtraCodeWebpackPlugin = require('extra-code-webpack-plugin')
module.exports = {
  ...
  plugins:[
    new ExtraCodeWebpackPlugin({
      exclude:/node_modules/, // exclude files
      codes:`console.log('extra codes!')` // codes to add 
    })
  ]
}

```

## params

```
class ExtraCodeWebpackPlugin {
  /**
   * 
   * @param {object} config
   * @param {RegExp} config.exclude  default /node_modules/
   * @param {string|function({isDev:boolean,isEntry:boolean,modulePath:string}, webpackOption:object): string} config.codes default ''
   */
  constructor(config = {}) {}
}
```

## 使用案例 | example use case 

HMR 增加 module.hot.accept 代码 | add HMR hot accept

```
new ExtraCodeWebpackPlugin({ codes: ({ isDev, isEntry }) => (isEntry && isDev) ? `module.hot.accept()` : `` })
```


增加（谷歌/百度）统计代码 | add (google) analytics code

```
new ExtraCodeWebpackPlugin({ codes: ({ modulePath,isDev }) => 
  (!isDev && !relative(modulePath, join(__dirname, 'index.mjs'))) ? `'analytics code'` : `` })
```

---
_Source: https://npm.io/package/extra-code-webpack-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
