Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share class name between JavaScript and SASS with Webpack?

Tags:

webpack

How can I share a class name as a variable between my JavaScript and SASS with Webpack?

Im already sharing an integer this way:

In my SASS:

$animationSpeed: 400;
:export {
  animationSpeed: $animationSpeed;
}

In my JS:

import styles from './styles.scss';
const animationSpeed = parseInt(styles.animationSpeed);

I can make the classname a variable with this in my SASS:

$animationClass: item--animating;
:export {
  animationClass: $animationClass;
}
.#{$animationClass} {
  // styles here
}

However this in my JS doenst work. I assume its because parseInt is for integers.

const animationClass = parseInt(styles.animationClass);
like image 488
Evanss Avatar asked Sep 01 '17 11:09

Evanss


1 Answers

Doh! It was really simple:

$animationClass: item--animating;
:export {
  animationClass: $animationClass;
}
.#{$animationClass} {
  // styles here
}

import styles from './styles.scss';
const animationClass = styles.animationClass;
like image 169
Evanss Avatar answered Nov 11 '22 20:11

Evanss