# rollup-plugin-replace-ast

> rollup插件，使用AST方式的rollup-plugin-replace类似插件

Latest version **1.0.5** (published 2020-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-replace-ast
pnpm add rollup-plugin-replace-ast
yarn add rollup-plugin-replace-ast
bun add rollup-plugin-replace-ast
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-03-15 |
| First published | 2019-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | 潘丽敏 |
| Maintainers | idler8 |
| Keywords | rollup, rollup-plugin, es2015, npm, modules |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-replace-ast
- Repository: https://github.com/idler8/rollup-plugin-replace-ast
- Issues: https://github.com/idler8/rollup-plugin-replace-ast/issues
- npm.io page: https://npm.io/package/rollup-plugin-replace-ast

## Dependencies (3)

- [magic-string](https://npm.io/package/magic-string.md) ^0.25.2
- [estree-walker](https://npm.io/package/estree-walker.md) ^0.8.1
- [rollup-pluginutils](https://npm.io/package/rollup-pluginutils.md) ^2.6.0

## 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

- 1.0.5 (latest) — 2020-03-15
- 1.0.4 — 2020-03-14
- 1.0.3 — 2019-11-26
- 1.0.2 — 2019-10-13
- 1.0.1 — 2019-10-12
- 1.0.0 — 2019-10-12

## README

# rollup-plugin-replace-ast
![npm](https://img.shields.io/npm/dm/rollup-plugin-replace-ast)

![npm](https://img.shields.io/npm/v/rollup-plugin-replace-ast) ![npm bundle size](https://img.shields.io/bundlephobia/min/rollup-plugin-replace-ast) ![GitHub top language](https://img.shields.io/github/languages/top/idler8/rollup-plugin-replace-ast)

使用AST替换全局ENV变量，类似rollup-plugin-replace，得到的内容更加简洁


## 安装

```bash
npm install --save-dev rollup-plugin-replace-ast
```


## 用法


```javascript
// rollup.config.js
import replace from 'rollup-plugin-replace-ast';

export default {
  // ...
  plugins: [
    replace({
        mode: 'production',
        resources: { img: ['image1'], png: ['png1', { path: 'png2' }] },
    });
  ]
};
```


## 配置

```javascript
{
  // 允许的文件范围
  include: 'config.js',

  // 排除的文件范围
  exclude: 'node_modules/**',
  // 替换变量
  values: {
    version: '1.0.0',
    mode: JSON.stringify('development')
  }
  // 所有其它键都将被用来替换变量
  version: '1.0.0',
  mode: JSON.stringify('development'),

}
```


## 例子

```javascript
replace({
    mode: 'production',
    resources: { img: ['image1'], png: ['png1', { path: 'png2' }] },
});
```

源代码:

```js
const code = [
    ENV.mode,
    ENV.resources,
    ENV.resources.png[1],
    ENV.other
];
```

替换后:

```js
const code = [
    'production',
    { img: ['image1'], png: ['png1', { path: 'png2' }] },
    { path: 'png2' },
    undefined
];
```



## License

MIT

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