rollup-plugin-node-resolve 插件允许我们加载node第三方模块依赖

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. resolve({
  5. extensions: ['.js', '.ts', '.tsx'],
  6. }),
  7. ]
  8. }

rollup-plugin-commonjs commonjs模块依赖转换为ES6插件

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. commonjs({ include: 'node_modules/**' }),
  5. ]
  6. }

TS转换插件

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. typescript({
  5. tsconfigOverride: {
  6. compilerOptions: { declaration: true, declarationDir: 'esm' },
  7. },
  8. }),
  9. ]
  10. }

rollup/plugin-eslint ESlint 校验插件

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. eslint({
  5. throwOnError: true,
  6. include: ['src/**/*.ts'],
  7. exclude: ['node_modules/**', 'lib/**']
  8. })
  9. ]
  10. }

rollup-plugin-babel babel转译插件

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. babel({
  5. runtimeHelpers: true,
  6. exclude: 'node_modules/**'
  7. })
  8. ]
  9. }

rollup-plugin-terser压缩代码插件

  1. //import {uglify} from 'rollup-plugin-uglify'; 也是压缩代码插件
  2. const isProduction = process.env.NODE_ENV === 'production';
  3. export default {
  4. input: 'src/main.js'
  5. plugins:[
  6. isProduction &&
  7. terser({
  8. output: {
  9. comments: false,
  10. },
  11. }),
  12. ]
  13. }

rollup-rollup-plugin-replace环境变量设置

类比 Webpack 的 DefinePlugin , 可在源码中通过 process.env.NODE_ENV 用于构建区分 Development 与 Production 环境.

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. replace({
  5. ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
  6. }),
  7. ]
  8. }

rollup-plugin-json允许 rollup 从 JSON 文件中导入数据

  1. export default {
  2. input: 'src/main.js'
  3. plugins:[
  4. json()
  5. ]
  6. }

rollup-plugin-multi-input允许入口文件多个打包

  1. export default {
  2. input: 'src/**/*.js',
  3. output: 'dist',
  4. plugins:[
  5. multiInput({ relative: 'src/' }),
  6. ]
  7. }

image.png