-
Notifications
You must be signed in to change notification settings - Fork 27
Plan for Modular Sass? #8
Comments
Hi, |
@f15gdsy Are you referring to @import of partials (http://sass-lang.com/documentation/file.SASS_REFERENCE.html#partials) or are you referring to variable scope and content blocks (http://sass-lang.com/documentation/file.SASS_REFERENCE.html#variable_scope_and_content_blocks)? |
Sounds more like a CSS modules thing? |
in sass-inject import postCSSlocalByDefault from 'postcss-modules-local-by-default'
import postCSSextractImports from 'postcss-modules-extract-imports'
import postCSSscope from 'postcss-modules-scope'
import postCSSvalues from 'postcss-modules-values'
import PostCSSparser from './parser.js'
import resolvePath from './resolve-path.js' new compile function in the same file async function compile (scss, styleUrl) {
// compile module
const content = scss.content
const responseText = content.responseText
if (typeof content === 'string' && content === '' ||
typeof responseText !== 'undefined' && responseText === '') {
return ''
}
const sass = await importSass
let { status, text, formatted } = await new Promise(res => { // eslint-disable-line
sass.compile(content, scss.options, res)
})
if (status !== 0) {
throw formatted
}
// rewrite urls and copy assets if enabled
const pluginOptions = System.sassPluginOptions || {}
if (pluginOptions.rewriteUrl) {
const CssUrlRewriterModule = await System.import('css-url-rewriter-ex', __moduleName)
const CssUrlRewriter = CssUrlRewriterModule.default
const urlRewriter = new CssUrlRewriter({ root: System.baseURL })
text = urlRewriter.rewrite(styleUrl, text)
}
const postcss = await System.import('postcss', __moduleName)
const postCSSPlugins = [
postCSSvalues,
postCSSlocalByDefault,
postCSSextractImports,
postCSSscope
]
// apply autoprefixer if enabled
if (pluginOptions.autoprefixer) {
const autoprefixerOptions = pluginOptions.autoprefixer instanceof Object
? pluginOptions.autoprefixer
: undefined
const autoprefixer = await System.import('autoprefixer', __moduleName)
postCSSPlugins.push(autoprefixer(autoprefixerOptions))
}
//
const postCSSparser = new PostCSSparser()
postCSSPlugins.push(postCSSparser.plugin)
// Run
const { css } = await postcss(postCSSPlugins).process(text, { from: '/' })
text = css
// inject module and remove old module
injectStyle(text, styleUrl)
// return an empty module in the module pipeline itself
return `export default ${JSON.stringify(postCSSparser.exportTokens)}`
} parser.js is here: the only tweak there is the plugin line which no longer goes up the whole tree
there's no speed improvement in removing it maybe a hash would help |
Hi, do you have plan for modular sass? Like supporting local scope?
The text was updated successfully, but these errors were encountered: