JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7105
  • Score
    100M100P100Q136336F
  • License ISC

Babel plugin for transpile scss or sass imports to css and embedding them in the head of the document

Package Exports

  • babel-plugin-transform-scss

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-transform-scss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

babel-plugin-transform-scss

Babel plugin for converting scss or sass imports to css and embedding them in the head of the document

This plugin completely replaces the standard webpack sass-loader. This part of code can be removed:

module: {
  rules: [
    //rules
    {
      test: /\.s[ac]ss$/i,
      use: ['style-loader', 'css-loader', 'sass-loader']
    }
  ]
}

Installation

npm install babel-plugin-transform-scss or yarn add babel-plugin-transform-scss

Use it in your config file:

{
  "presets": [],
  "plugins": [
    "babel-plugin-transform-scss"
  ]
}

How it works

This plugin will convert all scss or sass imports to the standard <style> attribute. For example:

import React from 'react'
import 'style.scss'

const Button = () => {
  return (
    <div className="button">
      Custom button
    </div>
  )
}

export default Button

import "style.scss" will be transformed to css and will be added to the head of the document:

<style data-scss-component="Button_style">
    .button {
      display: flex;
      justify-content: space-around;
    }
</style>

if import contains more than one styles:

import React from 'react'
import 'style.scss'
import 'style2.scss'

const Button = () => {
  return (
    <div className="button">
      <div className="nested-from-style2">Nested</div>
    </div>
  )
}

export default Button

imported styles will be replaced like this:

<style data-scss-component="Button_style">
    .button {
      display: flex;
      justify-content: space-around;
    }
</style>
<style data-scss-component="Button_style2">
    .nested-from-style2 {
      display: grid;
    }
</style>