naive-ui/build/naiveSCSSVarPlugin.js
2020-02-13 22:22:04 +08:00

32 lines
748 B
JavaScript

const sass = require('node-sass')
const path = require('path')
function createStyleScheme (css) {
return css
.replace(':export', 'export default')
.replace(/:\s/g, `: '`)
.replace(/;/g, `',`)
}
module.exports = function naiveSCSSExportVariable () {
return {
name: 'naive-scss-export-variable',
resolveId (source, importer) {
if (source.endsWith('.scss')) {
return path.resolve(path.dirname(importer), source)
}
return null
},
load (id) {
if (id.endsWith('.scss')) {
const css = sass.renderSync({
file: id,
outputStyle: 'expanded'
}).css.toString()
const styleScheme = createStyleScheme(css)
return styleScheme
}
}
}
}