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

@stencil/sass

Package Overview
Dependencies
Maintainers
11
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencil/sass

The Stencil Sass Plugin

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47K
increased by1.46%
Maintainers
11
Weekly downloads
 
Created
Source

@stencil/sass

This package is used to easily precompile Sass files within Stencil components. Internally this plugin uses a pure JavaScript implementation of Sass. Please see the Behavioral Differences from Ruby Sass doc if issues have surfaced since upgrading from previous versions which used used the node-sass implementation.

First, npm install within the project:

npm install @stencil/sass --save-dev

Next, within the project's stencil config, import the plugin and add it to the config's plugins property:

stencil.config.ts
import { Config } from '@stencil/core';
import { sass } from '@stencil/sass';

export const config: Config = {
  plugins: [
    sass()
  ]
};

During development, this plugin will kick-in for .scss or .sass style urls, and precompile them to CSS.

Options

Sass options can be passed to the plugin within the stencil config, which are used directly by sass. Please reference sass documentation for all available options. Note that this plugin automatically adds the component's directory to the includePaths array.

Inject Globals Sass Paths

The injectGlobalPaths config is an array of paths that automatically get added as imports to all components. This can be useful to inject Sass variables, mixins and functions to override defaults of external collections. For example, apps can override default Sass variables of Ionic components. Relative paths within injectGlobalPaths should be relative to the stencil config file.

v1

v1.x of stencil/sass uses sass @import syntax to add files listed in the injectGlobalPaths option to each stylesheet. Do not use @use in your components if using v1 because it is not permitted by sass to have @import statements before @use statements. Below is an example of using injectGlobalPaths in v1.

exports.config = {
  plugins: [
    sass({
      injectGlobalPaths: [
        'src/global/variables.scss', //adds @import 'src/global/variables.scss' statement
        'src/global/mixins.scss' //adds @import 'src/global/mixins.scss' statement
      ]
    })
  ]
};
v2

v2.x of stencil/sass uses sass @use syntax to add files listed in injectGlobalPaths to each stylesheet. Because the @use syntax also supports namespacing by default, the option is now available to customize the namespace. injectGlobalPaths can now be an array of TS tuples. The first position is the filepath and the second position is the namespace. There is still the option to only use a string, which will default the namespace to the name of the file. These methods can be combined.

exports.config = {
  plugins: [
    sass({
      injectGlobalPaths: [
        ['src/global/variables.scss', 'var'], //adds "@use 'src/global/variables.scss' as var" statement
        ['src/global/mixins.scss', '*'], //root namespace, no prefix needed to access
        'src/global/animations.scss' //namespace defaults to 'animations'
      ]
    })
  ]
};

Note that each of these files are always added to each component, so in most cases they shouldn't contain CSS because it'll get duplicated in each component. Instead, injectGlobalPaths should only be used for Sass variables, mixins and functions, but does not contain any CSS.

Contributing

Please see our Contributor Code of Conduct for information on our rules of conduct.

Keywords

FAQs

Package last updated on 11 Nov 2020

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