Here are some settings we've used to import some open source code libraries, along with some quick points highlighting why the approach was taken in each case.

Where possible we have re-used existing preset files from the live repos to show you how to do that in different situations. In practice you may want to create a curated set of preset files containing the most useful configurations for your designers to use in their design tools.

Javascript libraries

Reactstrap

Javascript library generating presets from javascript files. Uses external css.

Reactstrap is a set of React components that act as a wrapper for the Bootstrap CSS library. The react components themselves don't contain the bootstrap CSS, but instead require it to be included on any web page using the reactstrap components.

The import steps we used for Reactstrap are:

  1. git clone <https://github.com/reactstrap/reactstrap> to clone a local copy of the repo
  2. yarn to install the package dependencies
  3. yarn build to run the existing reactstrap build - building src/index.js into dist/reactstrap.js
  4. Inspect the repo to find where the files to use for preset are stored - in this case in docs/lib/examples/*.js
  5. interplay to run the CLI, entering enter the settings below:

module.exports = () => {

   return {
      framework: "react",
      presetPaths: [
         "docs/lib/examples/*.js"
      ],
      includePaths: [
         "<https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css>"
      ],
      deployPaths: [],
      packages: [
         {
            name: "reactstrap",
            packagePath: "./package.json", 
            src: "src/index.js",
            build: "dist/reactstrap.js"
         }
      ],
      devBuild: true,
      presetRules: [
			{
				presetPath: ".*/{componentName}.",
				limit: 3
			},
			{
				presetPath: "{componentName}/",
				limit: 3
			},
		],
   }
}

In this case we enter the full URL to the css we want included on every page using the components, because it is not a local file. For other libraries we can enter a relative path here to deploy and include the local CSS that is produced in their build.

The CLI will:

Typescript libraries

Ant Design

Typescript library with markdown example files

For our sample import we will use the CSS file that is output from the build.

  1. git clone <https://github.com/ant-design/ant-design.git> to clone a local copy of the repo
  2. yarn to install the package dependencies
  3. yarn build to run the repo build. This outputs the build as dist/antd.js and dist/antd.css
  4. Inspect the repo to find where the example files are - in this case they are in markdown files in demo folders alongside each component. So we use a wildcard for the component folder name and another wildcard for the filename: components/*/demo/*.md
  5. interplay to run the CLI, entering enter the settings below:
module.exports = () => {
    return {
      framework: "react",
      packages: [
        {
          name: "antd",
          packagePath: "./package.json",
          src: "components/index.tsx",
          build: "dist/antd.js"
        }
     ],
      includePaths: [
        "dist/antd.css"
      ],
      deployPaths: [],
      presetPaths: [
        "components/*/demo/*.md"
      ],
      peerDependencies: {},
      presetRules: [
        {
	        //match component instances whose name matches first part of filename
	        presetPath: ".*/{componentName}.",
	        limit: 5
        },
        {
	        //match component instances whose name matches folder in file path
	        presetPath: "{componentName}/",
	        limit: 5
	       }
        //add more preset rules here
      ]
    };
  };