Created
May 6, 2020 14:22
-
-
Save M-O-Z-G/18c47b5f74e2e3206dcc427efd4ddf71 to your computer and use it in GitHub Desktop.
Base Riot.JS config template with Pug+TypeScript+Stylus precompilers. Use `stylus = require('stylus')` if you use it outside any Gulp environment. It was just the my case, and I want to keep it like it is.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { registerPreprocessor } = require('@riotjs/compiler'), | |
pug = require('pug'), | |
ts = require('typescript'), | |
stylus = require('gulp-stylus').stylus; | |
registerPreprocessor('template', 'pug', function(code, { options }) { | |
const { file } = options | |
console.log('Compile the Pug code in', file) | |
return { | |
code: pug.render(code, { | |
filename: file, | |
pretty: true, | |
doctype: 'html' | |
}) | |
} | |
}) | |
registerPreprocessor('css', 'stylus', function(code, { options }) { | |
const { file } = options | |
console.log('Compile the Stylus code in', file) | |
const css = stylus.render(code); | |
return { | |
code: css.toString(), | |
map: null | |
} | |
}) | |
// registerPreprocessor('css', 'sass', function(code, { options }) { | |
// const { file } = options | |
// console.log('Compile the sass code in', file) | |
// const {css} = sass.renderSync({ | |
// data: code | |
// }) | |
// return { | |
// code: css.toString(), | |
// map: null | |
// } | |
// }) | |
registerPreprocessor('javascript', 'ts', function(code, { options }) { | |
const { file } = options | |
console.log('Compile the TypeScript code in', file) | |
const result = ts.transpileModule(code, { | |
fileName: file, | |
compilerOptions: { | |
module: ts.ModuleKind.ESNext | |
} | |
}) | |
return { | |
code: result.outputText, | |
map: null | |
} | |
}) | |
module.exports = { | |
hot: false, // set it to true if you are using hmr | |
// add here all the other @riotjs/compiler options riot.js.org/compiler | |
javascipt: 'ts', | |
template: 'pug', | |
css: 'stylus' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment