Rocketact

Rocketact

  • Docs
  • GitHub

›Plugins

Getting Started

  • Getting Started
  • Folder Structure
  • Available Scripts
  • Supported Browsers and Features
  • Custom Templates

Development

  • Managing Dependencies
  • Adding Pages
  • Adding Stylesheets
  • Post-Processing CSS
  • Adding Images
  • Http proxy

Deployment

  • Public Path

Plugins

  • What is the plugin?
  • rocketact-plugin-polyfill
  • rocketact-plugin-bundle-analyzer
  • Plugin template
  • Awesome Plugins
Edit

What is the plugin?

Rocketact leverages various plugins to implements various features. You can think of plugins as the "API" to modify Rocketact's behaviour.

How Rocketact works?

Rocketact at its core leverages webpack and webpack-dev-server to handle the bundle operation and development environment. We use webpack-chain to simplify the management of webpack's configuration.

Rocketact use plugin APIs internally to create builtin commands and compose webpack configurations.

How plugins works?

The plugin interface contains three API:

api.registerCommand(subcommand: string, () => Promise<any>): void

Register a new sub-command. Then you can run:

npx rocketact-scripts subcommand

or configure it in npm scripts.

The second argument is called without parameters.

api.resolveWebpackConfig(): webpack.Configuration

Returns a plain webpack configuration object.

api.chainWebpack((webpackChain: Config) => void)

Use this API to manipulate the default webpack configuration in Rocketact.

How to use a plugin?

Local plugin

Basiclly, every JavaScript file could be a valid plugin, all you need to do is make sure its exports object is a function accepts the plugin interface API as parameter.

Following is a simple example showing how to configure babel-plugin-import for antd:

Create a file named rocketactPlugin.js in your project's root folder with following content:

const merge = require("babel-merge");

module.exports = api => {
  api.chainWebpack(webpackChain => {
    webpackChain.module
      .rule("compile")
      .use("babel")
      .tap(options =>
        merge(options, {
          plugins: [[require.resolve("babel-plugin-import"), {
            "libraryName": "antd",
            "style": "css"
          }]]
        })
      );
  });
};

Then tell Rocketact to load that file by adding a new rocketactPlugins filed in package.json:

  "rocketactPlugins": [
    "./rocketactPlugin"
  ]

Installed plugin

If you want to share your plugin with other developers. The best way to achieve this is to publish your plugin as a npm package.

The only restriction is the package name must follow the rocketact-plugin- prefix.

All the plugin users need to do is install it as a dev dependency and no other configuration is needed.

Last updated on 4/15/2019 by loveky
← Public Pathrocketact-plugin-polyfill →
  • How Rocketact works?
  • How plugins works?
    • api.registerCommand(subcommand: string, () => Promise<any>): void
    • api.resolveWebpackConfig(): webpack.Configuration
    • api.chainWebpack((webpackChain: Config) => void)
  • How to use a plugin?
    • Local plugin
    • Installed plugin
Rocketact
Docs
Getting Started
Community
User ShowcaseIssues
More
GitHubStar
Copyright © 2018-present Rocketact documentation authors.