rollup-plugin-replace-ast

1.0.5 • Public • Published

rollup-plugin-replace-ast

npm

npm npm bundle size GitHub top language

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

安装

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

用法

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

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

配置

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

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

}

例子

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

源代码:

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

替换后:

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

License

MIT

Package Sidebar

Install

npm i rollup-plugin-replace-ast

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

9.66 kB

Total Files

6

Last publish

Collaborators

  • idler8