Socket
Socket
Sign inDemoInstall

svelte-preprocess-vars

Package Overview
Dependencies
181
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    svelte-preprocess-vars

Svelte preprocessor to inject JS variables into component styles


Version published
Maintainers
1
Install size
147 kB
Created

Readme

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

Last updated on 25 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc