rollup插件

rollup插件

1.rollup-plugin-buble插件

rollup.js打包的过程中进行代码编译,将ES6+代码编译成ES2015标准
npm i -D rollup-plugin-buble

配置文件里引入

import buble from 'rollup-plugin-buble'
export default {
  input: ...,
  output: ...,
  plugins: [
    buble()//使用resolve
  ]
}

2. rollup-plugin-alias插件

alias插件提供了为模块起别名的功能
npm i -D rollup-plugin-alias
配置文件里引入

import alias from 'rollup-plugin-alias'
export default {
  input: ...,
  output: ...,
  plugins: [
    alias({
      resolve: ['.jsx', '.js'],
      entries: {
        something: '../../../something',
        'somelibrary-1.0.0': './mylocallibrary-1.5.0',
      }
    })
  ]
}

3.rollup-plugin-flow-no-whitespace插件

flow插件用于在rollup.js打包过程中清除flow类型检查部分的代码
npm i -D rollup-plugin-flow-no-whitespace

import flow from 'rollup-plugin-flow-no-whitespace'
export default {
  input: ...,
  output: ...,
  plugins: [
   flow()//使用flow
  ]
}

4.rollup-plugin-replace插件

replace插件的用途是在打包时动态替换代码中的内容
npm i -D rollup-plugin-replace

import replace from 'rollup-plugin-replace'
export default {
  input: ...,
  output: ...,
  plugins: [
  replace({
      __SAM__: true //将__SAM__替换为true
    }),
  ]
}

5.rollup-plugin-terser插件

rollup.js打包过程中实现代码压缩
npm i -D rollup-plugin-terser

import { terser } from 'rollup-plugin-terser'
export default {
  input: ...,
  output: ...,
  plugins: [
  terser({
      output: {
        ascii_only: true // 仅输出ascii字符
      },
      compress: {
        pure_funcs: ['console.log'] // 去掉console.log函数
      }
    }),
  ]
}

6.intro和outro配置

打包配置
intro:在打包好的文件的块的内部(wrapper内部)的最顶部插入一段内容
outro:在打包好的文件的块的内部(wrapper内部)的最底部插入一段内容
banner:在打包好的文件的块的外部(wrapper外部)的最顶部插入一段内容
footer:在打包好的文件的块的外部(wrapper外部)的最底部插入一段内容

export default {
  input: ...,
  output: ...,
  plugins: [
    {
      intro: '// this is a intro comment',
      outro: '// this is a outro comment'
    }
  ]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhao1239902

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值