Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Yemolai/07aa28498858f6d8e02af23f3e2e8825 to your computer and use it in GitHub Desktop.
Save Yemolai/07aa28498858f6d8e02af23f3e2e8825 to your computer and use it in GitHub Desktop.
Make environment variables available as Sass variables in Vue.js

Vue.js: Environment variables in Sass

Make environment variables available as Sass variables in Vue.js.

CONDITION="true"
COLOR="red"
<template>
<div class="example">
Example
</div>
</template>
<script>
export default {
name: 'Example'
}
</script>
<style lang="scss">
.example {
color: black;
@if $CONDITION == true {
color: $COLOR;
}
}
</style>
module.exports = {
css: {
loaderOptions: {
sass: {
data: `
$CONDITION: ${process.env.CONDITION || 'false'};
$COLOR: ${process.env.COLOR};
`
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment