Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-preprocess-vars

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-preprocess-vars

Svelte preprocessor to inject JS variables into component styles

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

svelte-preprocess-vars

Svelte preprocessor to inject JS variables into component styles.

Takes:

module.exports = {
  primaryColor: 'blue',
};

and converts:

<style>
  h1 {
    color: var(--primaryColor);
  }
</style>

to:

<style>
  h1 {
    color: blue;
  }
</style>

Setup:

npm install svelte-preprocess-vars --save-dev

Example webpack svelte-loader config:

const path = require('path');
const webpack = require('webpack');
const sveltePreprocessVars = require('svelte-preprocess-vars');

const variablesPath = path.resolve('shared-variables.js');

module.exports = {
  module: {
    rules: [
      {
        test: /\.(html)$/,
        use: {
          loader: 'svelte-loader',
          options: {
            hydratable: true,
            hotReload: true,
            preprocess: sveltePreprocessVars(variablesPath),
            externalDependencies: [variablesPath]  // ensures svelte-loader recompiles the components if the variables change
          }
        }
      }
    ]
  },
};

Webpack and svelte-loader won't watch these variables unless you include them in your 'externalDependencies' (see example above).

FAQs

Package last updated on 25 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc