# webpack-plugin-replace-api

> a plugin for webpack to replace api

Latest version **0.0.6** (published 2019-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install webpack-plugin-replace-api
pnpm add webpack-plugin-replace-api
yarn add webpack-plugin-replace-api
bun add webpack-plugin-replace-api
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2019-10-22 |
| First published | 2019-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | krisguoqin |
| Maintainers | krisguoqin |
| Keywords | webpack, plugin, replace-api |

## Links

- npm: https://www.npmjs.com/package/webpack-plugin-replace-api
- Repository: https://github.com/KrisGuoQin/webpack-plugin-replace-api
- Homepage: https://github.com/KrisGuoQin/webpack-plugin-replace-api#readme
- Issues: https://github.com/KrisGuoQin/webpack-plugin-replace-api/issues
- npm.io page: https://npm.io/package/webpack-plugin-replace-api

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2019-10-22
- 0.0.5 — 2019-10-22
- 0.0.4 — 2019-10-21
- 0.0.3 — 2019-10-21
- 0.0.2 — 2019-10-21
- 0.0.1 — 2019-10-21
- 0.0.0 — 2019-10-21

## README

<!--
 * @Description: 
 * @Author: GuoQin
 * @Date: 2019-10-21 22:35:42
 * @LastEditors: GuoQin
 * @LastEditTime: 2019-10-22 11:08:25
 -->
# webpack-plugin-replace-api

项目中的接口地址可能来自多个域名，开发环境可以使用**devServer**配置代理解决。
一般情况下可以使用判断运行环境的形式，来加上接口的域名信息，可能要写多次的判断。
所以这里使用webpack插件来解决。**(请在充分明白的情况下，谨慎使用)。

### 使用方式

```javascript
const WebpackPluginReplaceApi = require('webpack-plugin-replace-api');

const ReplaceApiOptions = [
    {
        test: /\/mobile/g,
        target: 'http://127.0.0.1'
    },
    {
        test: /\/pc/g,
        target: 'http://127.0.0.2'
    }
];

...

// mode: production

module.exports = {
    plugins: [
        new WebpackPluginReplaceApi(ReplaceApiOptions)
    ]
}
```

## CHANGELOG
CHANGELOG.md

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