Created
June 25, 2020 15:44
-
-
Save calebdwilliams/b3d6b2c2ca242e8aec5acafd0a532db2 to your computer and use it in GitHub Desktop.
Rollup Plugin LitElement SCSS
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
import sass from 'node-sass'; | |
import { resolve, extname } from 'path'; | |
import { processString } from 'uglifycss'; | |
import stringToTemplateLiteral from 'string-to-template-literal'; | |
import nodeSassImporter from 'node-sass-package-importer'; | |
const importer = nodeSassImporter(); | |
function transform(css) { | |
return `import { css } from 'lit-element'; | |
export default css${stringToTemplateLiteral(css)};`; | |
} | |
function isScss(id) { | |
return extname(id) === '.scss'; | |
} | |
export default function css() { | |
return { | |
name: 'lit-scss', | |
load(id) { | |
if (isScss(id)) { | |
this.addWatchFile(resolve(id)); | |
} | |
}, | |
transform(data, id) { | |
if (!isScss(id)) { | |
return; | |
} | |
const output = sass.renderSync({ | |
data, | |
importer, | |
}).css; | |
const css = processString(output.toString(), {}); | |
const code = transform(css); | |
return { code, map: { mappings: '' } }; | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment