theo loader for webpack
A webpack loader that transforms Design Tokens files using Salesforce's theo.
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
// => {// COLOR_BACKGROUND: "rgb(244, 246, 249)",// COLOR_BACKGROUND_ALT: "rgb(255, 255, 255)"// }
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:
;// => "$color-background: rgb(244, 246, 249);\n$color-background-alt: rgb(255, 255, 255);"
or you can use the shorthand:
;// => "$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
moduleexports = ... module: rules: test: /\.json$/ loader: "theo-loader" plugins: 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 { let newOptions = prevOptions; const formatOptions = prevOptions && prevOptionsformat || {}; const formatType = formattype; if formatType === 'scss' newOptions = ...prevOptions format: ...formatOptions // SCSS variables will be named by applying 'PREFIX_' to the // front of the token name prop ; 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:
; // Do any theo initialization heretheo; moduleexports = ... module: rules: test: /\.json$/ loader: "theo-loader" plugins: options: theo: // Configure theo-loader here ...