Babel plugin for transforming SCSS imports to static variable declarations with transpiled CSS string
npm install @researchgate/babel-plugin-transform-scss-import-to-stringBabel transform plugin for replacing \*.scss imports with static variable
declaration as css string.
``js`
import sideEffectStyles from './styles.sass';
// vvv
const sideEffectStyles = '.foo { color: red; }';
Install the plugin first:
`shyarn
yarn add --dev @researchgate/babel-plugin-transform-scss-import-to-string
Add it to your babel configuration:
`json
{
"plugins": ["@researchgate/babel-plugin-transform-scss-import-to-string"]
}
`node-sass options:`json
{
"plugins": [
[
"@researchgate/babel-plugin-transform-scss-import-to-string",
{ "precision": 3 }
]
]
}
`Import \*.scss files:
`scss
// foo.scss
$bar: 42px;
.foo {
font-size: $bar;
}
``js
// foo.js
import foo from './foo.scss';
console.log(foo); // -> .foo { font-size: 42px; }
`Requirements
-
node-sass, which you should install explicitly
- babel-core`, which you should already have with babel configured- This module shouldn't be used with webpack and sass-loader since babel
transform would take first place in build process.
- Every import transpiled with node-sass as an independent file, so you have to
explicitly import dependencies if you used to have common context before.