Skip to content

Instantly share code, notes, and snippets.

@phun-ky
Last active November 26, 2019 10:52
Show Gist options
  • Save phun-ky/be2a1cccae5f8c2de229d8a218267e72 to your computer and use it in GitHub Desktop.
Save phun-ky/be2a1cccae5f8c2de229d8a218267e72 to your computer and use it in GitHub Desktop.
const compiler= require("@riotjs/compiler")
const sass = require('node-sass')
const stylus = require('stulys')
import IF_COLORS_SUPPORT from '@guybrush/color/src/support';
compiler.registerPreprocessor('css', 'sass', function(code, { options }) {
const { file } = options;
console.log('Compile the sass code in', file);
const result = sass.renderSync({
file,
data: code
});
return {
code: result.css.toString(),
map: null
};
});
// or stylus
compiler.registerPreprocessor('css', 'stylus', function(code, { options }) {
const { file } = options;
console.log('Compile the stylus code in', file);
const styl = stylus(code);
const result = styl.render();
return {
code: result.toString(),
map: null
};
});
const { code } = compiler.compile(`
<my-component>
<p>{ message }</p>
<style type="sass">
p {
color: ${IF_COLORS_SUPPORT.blue.rgb}
}
</style>
<style type="stylus">
p
color ${IF_COLORS_SUPPORT.blue.rgb}
</style>
<script>
export default {
message: 'hello'
}
</script>
</my-component>
`)
console.log(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment