• Stars
    star
    245
  • Rank 161,704 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Export tool for Figma. You can easily and automatically export your Figma components and use them directly into your website.

Export tool for Figma.

You can easily and automatically export your figma components and styles and use them directly into your website.

Test Coverage Status Sponsor

✨ In Short

Components

You can export your Figma Components as SVG and use them inside your website.

This is particularly useful when you have your own icon set and you want to keep your website icons up-to-date with your Figma file.

Styles

You can export your Figma Styles into different output like .sass format, .scss format, Style Dictionary tokens or you can create your own outputter.

If you want to keep the style of your Figma file in-sync with the .css of your website, this is a must-have.

🎨 Colors (paints)

  • Color
  • Linear Gradient

🍭 Effects

Shadow and Blur effects cannot be combined together since they use two different CSS properties.

  • Inner Shadow
  • Drop Shadow
  • Layer Blur

✏️ Text

  • font-family
  • font-weight
  • font-size
  • line-height
  • letter-spacing
  • font-style
  • font-variant
  • text-transform
  • text-decoration
  • text-align

πŸ—οΈ Personal Access Token

First of all you have to set the environment variable FIGMA_TOKEN.

To do so, you need a Personal Access Token. You can generate one from your Account Settings.

Figma - Account Menu

Inside the Account Settings click on Create a new personal access token and enter a description.

Copy the token, this is your only chance to do so!

export FIGMA_TOKEN=<personalAccessToken>

You can use dotenv or export the variable using .bash_profile/.bashrc file.

πŸ§ͺ Just Try

If you wanna try it just run following command and you will be able to download all components from https://www.figma.com/file/fzYhvQpqwhZDUImRz431Qo as .svg 😎

# export figma token
export FIGMA_TOKEN=<personalAccessToken>

# export figma components as svg
npx -p @figma-export/cli -p @figma-export/output-components-as-svg figma-export components fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-components-as-svg

or you can export all styles into .scss

# export figma token
export FIGMA_TOKEN=<personalAccessToken>

# export figma styles as .scss variables
npx -p @figma-export/cli -p @figma-export/output-styles-as-sass figma-export styles fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-styles-as-sass

πŸ“¦ Packages

@figma-export/core

This package contains the core functionalities for figma-export. You can download and use it as a dependency of your project.

@figma-export/cli

This package allows you to consume all core functionalities from your terminal.

πŸ“– Usage

Typically you'll prefer to use the cli. Here different ways to do the same:

Build Process

You can use figma-export as part of your build process.

npm install --save-dev @figma-export/cli @figma-export/output-components-as-svg @figma-export/output-styles-as-sass

# or using `yarn`
yarn add @figma-export/cli @figma-export/output-components-as-svg @figma-export/output-styles-as-sass --dev

Now you can create a script command inside your package.json.

Following an example:

{
  "scripts": {
+   "figma:export-components": "figma-export components fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-components-as-svg",
+   "figma:export-styles": "figma-export styles fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-styles-as-sass",
  }
}

Use it on the fly

Alternatively you can use npx to use it on the fly:

npx @figma-export/cli --help

Global Setup

You can also install it as a global dependency:

npm install -g @figma-export/cli

# or using `yarn`
yarn add @figma-export/cli --global
figma-export --help

Advanced

Last but not least, you can create a configuration file and use a single command to rule them all πŸ’

Let's create the file .figmaexportrc.js and paste the following:

module.exports = {

    commands: [

        ['styles', {
            fileId: 'fzYhvQpqwhZDUImRz431Qo',
            // version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
            // onlyFromPages: ['icons'], // optional - Figma page names (all pages when not specified)
            outputters: [
                require('@figma-export/output-styles-as-sass')({
                    output: './output/styles'
                })
            ]
        }],

        ['components', {
            fileId: 'fzYhvQpqwhZDUImRz431Qo',
            // version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
            onlyFromPages: ['icons'],
            // filterComponent: (component) => !/^figma/.test(component.name), // optional
            transformers: [
                require('@figma-export/transform-svg-with-svgo')({
                    plugins: [
                        {
                            name: 'preset-default',
                            params: {
                                overrides: {
                                    removeViewBox: false,
                                }
                            }
                        },
                        {
                            name: 'removeDimensions',
                            active: true
                        }
                    ]
                })
            ],
            outputters: [
                require('@figma-export/output-components-as-svg')({
                    output: './output/components'
                })
            ]
        }]

    ]

};

ℹ️ Take a look at .figmaexportrc.example.js for more details.

now you can install the @figma-export dependencies that you need

npm install --save-dev @figma-export/cli @figma-export/output-styles-as-sass @figma-export/transform-svg-with-svgo @figma-export/output-components-as-svg @figma-export/output-styles-as-sass

and update the package.json.

{
  "scripts": {
+   "figma:export": "figma-export use-config"
  }
}

If needed you can also provide a different configuration file.

{
  "scripts": {
+   "figma:export": "figma-export use-config .figmaexportrc.production.js"
  }
}

TypeScript

If you prefer, you can create a .figmaexportrc.ts and use TypeScript instead. For doing so, you just need to install a few new dependencies in your project.

npm install --save-dev typescript ts-node @types/node @figma-export/types

and slightly change your package.json

{
  "scripts": {
+   "figma:export": "ts-node ./node_modules/@figma-export/cli/bin/run use-config .figmaexportrc.ts"
  }
}

Take a look at .figmaexportrc.example.ts for more details.

Node.js ESM

Node.js is now supporting ECMAScript modules (ESM).

If your package.json contains the "type": "module" field then you'll need to rename your .figmaexportrc.js configuration file:

-  .figmaexportrc.js
+  .figmaexportrc.cjs

and adjust the command you run:

figma-export use-config .figmaexportrc.cjs

If instead you're using the TypeScript setup you'll need to rename the .figmaexportrc.ts configuration file.

-  .figmaexportrc.ts
+  .figmaexportrc.cts

πŸ“š More Packages

For the list of all official packages or if you want to create your own transformer or outputter you can continue reading CLI Documentation.

More Repositories

1

video-to-markdown

How to embed a video in markdown? Here the answer. Add videos to your markdown files easier.
JavaScript
203
star
2

speedtest-for-digitalocean

Run speed tests for all DigitalOcean datacenters faster than ever.
JavaScript
41
star
3

bash_profile

A collection of bash utilities. Set and unset proxy. Completions for git, svn and ssh. PS1 customization.
Shell
18
star
4

wasm-vs-js-benchmark

A comparison between WebAssembly and Javascript.
JavaScript
13
star
5

jquery-jcreate

jCreate is a new special event for jQuery. Just use .on('create', ..); the callback will be triggered when elements are created on the page.
JavaScript
12
star
6

figma-plugin-run-github-actions-workflows

Run GitHub Actions workflows directly within Figma, using the selected page and nodes as inputs.
TypeScript
6
star
7

html-miner

A powerful miner that will scrape html pages for you. ` HTML Scraper Β΄
JavaScript
4
star
8

figma-export-pdfs-action

A GitHub Action that exports content from a Figma file as a PDF document.
TypeScript
4
star
9

contentful-migration-tool

Run Contentful migrations more easily with just one command. It makes migration processes a breeze.
TypeScript
3
star
10

hb-ejs

A Harp Boilerplate.
JavaScript
3
star
11

cv

This is my curriculum. It's just a PDF but with some cool behind the scenes.
TypeScript
2
star
12

marcomontalbano.github.io

My personal website.
Astro
2
star
13

an-introduction-to-frontend

A course I developed in 2017 to introduce backend developers and interns at Sopra Steria to the fundamentals of frontend development.
HTML
1
star
14

kata.js

A collection of katas with JavaScript.
TypeScript
1
star
15

numberun

NumbeRun is a puzzle game I developed in 2007 for my school-leaving examination. The game was developed in Microsoft Visual C# 2005 using the Microsoft XNA library.
Pascal
1
star