npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

theo-loader

v4.0.0

Published

A webpack loader that transforms Design Tokens files using Salesforce's theo

Downloads

37

Readme

theo loader for webpack

Greenkeeper badge

A webpack loader that transforms Design Tokens files using Salesforce's theo.

Build Status NPM Version Dependencies

Installation

npm install --save-dev webpack theo theo-loader

Note: npm deprecated auto-installing of peerDependencies from npm@3, so required peer dependencies like theo and webpack must be listed explicitly in your package.json.

Usage

props.json

{
  "aliases": {
    "WHITE": "#FFFFFF",
    "LINK_WATER": "#F4F6F9"
  },
  "props": {
    "COLOR_BACKGROUND": {
      "value": "{!LINK_WATER}",
      "comment": "Default background color for the whole app."
    },
    "COLOR_BACKGROUND_ALT": {
      "value": "{!WHITE}",
      "comment": "Second default background color for the app."
    }
  },
  "global": {
    "type": "color",
    "category": "background"
  }
}
import designTokens from 'theo-loader!./props.json'
// => {
//  COLOR_BACKGROUND: "rgb(244, 246, 249)",
//  COLOR_BACKGROUND_ALT: "rgb(255, 255, 255)"
// }

Documentation: Using loaders

Formats and Transforms

The loader uses the web transform and common.js format by default. You can specify another transform or format in the query parameters:

import designTokens from 'theo-loader?{"transform":{"type":"web"},"format":{"type":"scss"}!./props.json';
// => "$color-background: rgb(244, 246, 249);\n$color-background-alt: rgb(255, 255, 255);"

or you can use the shorthand:

import designTokens from 'theo-loader?transform=web&format=scss!./props.json';
// => "$color-background: rgb(244, 246, 249);\n$color-background-alt: rgb(255, 255, 255);"

You can specify other options to pass to theo via the LoaderOptionsPlugin in your webpack configuration:

webpack.config.js

module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.json$/,
        loader: "theo-loader"
      }
    ]
  },

  plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        theo: {
          // These options will be passed to Theo in all instances of theo-loader
          transform: {
            type: 'web'
          },

          // `getOptions` will be called per import
          // `prevOptions` will be a merged object of the options specified
          // above, as well as any passed to the loader via query string
          getOptions: (prevOptions) => {
            let newOptions = prevOptions;

            const formatOptions = (prevOptions && prevOptions.format) || {};
            const formatType = format.type;

            if (formatType === 'scss') {
              newOptions = {
                ...prevOptions,
                format: {
                  ...formatOptions,
                  // SCSS variables will be named by applying 'PREFIX_' to the
                  // front of the token name
                  propsMap: prop => prop.update('name', name => `PREFIX_${name}`)
                },
              };
            }

            return newOptions;
          }
        }
      }
    })
  ]
};

See the theo documentation for more information about the Theo options format.

theo Initialization

You can perform any initialization for theo, like registering custom transforms or formatters using registerTransform, registerValueTransform or registerFormat, in your webpack configuration:

import theo from 'theo';

// Do any theo initialization here
theo.registerValueTransform(
  'animation/web/curve',
  prop => prop.get('type') === 'animation-curve',
  prop => 'cubic-bezier(' + prop.get('value').join(', ') + ')'
);

module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.json$/,
        loader: "theo-loader"
      }
    ]
  },

  plugins: {
    new webpack.LoaderOptionsPlugin({
      options: {
        theo: {
          // Configure theo-loader here
          ...
        }
      }
    })
  }
}