svrx
  • Languages
  • svrx
  • svrx
    • SUMMARY
    • Contributing to svrx
    • Getting Started
    • Blog
      • Server-X: A Pluggable Platform For Local Frontend Development
    • Guide
      • API Reference
      • Option Reference
      • How To Use Routes
    • Plugins
      • How To Write A Plugin
      • How To Use Plugins
    • Practice
      • Integrations
      • Recipes
  • svrx
    • 概要
    • 贡献指南
    • 快速上手
    • Blog
      • Server-X:一款可能提升你十倍工作效率的工具
      • 使用 svrx 实现更优雅的接口 Mock
      • 说说 Server-X 的免安装插件机制
    • 进阶指南
      • API 索引
      • 参数列表
      • Routing 路由的使用
    • 插件体系
      • 如何写一个插件
      • 插件的使用
    • 项目实战
      • 结合主流脚手架使用
      • 特定场景使用
Powered by GitBook
On this page
  • 通过命令行
  • 通过.svrxrc.js配置
  • scope

Was this helpful?

  1. svrx
  2. 插件体系

插件的使用

通过命令行

你可以通过命令行的方式去使用插件,例如:

svrx --plugin markdown -p qrcode # -p 是 --plugin 的缩写
svrx --markdown --qrcode         # 在命令行中设置某个插件名为 true 也可以快速开启一个插件
svrx --plugin "qrcode?ui=false"  # 可以用 name?querystring 进行插件传参
svrx --plugin "webpack@0.0.3"    # name@version 可以声明插件版本

通过.svrxrc.js配置

同样的,你也可以通过配置 .svrxrc.js 中的 plugins 字段来启用或配置插件,如:

// .svrxrc.js
module.exports = {
  plugins: [
    'markdown',
    {
      name: 'qrcode',
      options: {
        ui: false,
      },
    },
    {
      name: 'webpack',
      version: '0.0.3',
    },
  ],
};

然后在项目根目录执行svrx命令, svrx会自动帮你安装markdown,qrcode和webpack插件,并运行它们。

scope

在使用这样的 scope 插件时,你可以通过 @<scope>/<name> 的格式来声明这个插件。

比如有一个插件包名为 svrx-plugin-foo,且它的 scope 为 bar,那么你可以通过下面的方式使用它:

svrx --@bar/foo 
svrx -p @bar/foo
svrx -p "@bar/foo@0.0.3"

或者:

// .svrxrc.js
module.exports = {
  plugins: [
    '@bar/foo',
    {
      name: '@bar/foo',
      options: {
        bar: false,
      },
    },
  ],
};
Previous如何写一个插件Next项目实战

Last updated 3 years ago

Was this helpful?

svrx 插件支持 。

你可以使用官方脚手架 一键创建带有 scope 的插件。

npm-scope
svrx-create-plugin