mixobj doesn't merge deeply
Closed this issue · 6 comments
My project structure looks like this
/tags
/example
example.tag
example.scss
/app
settings.scss
Within my tag I'd like to do the following
<example>
<style type="text/scss">
@import 'settings';
@import 'example';
</style>
</example>
By default the 2nd import works whereas the 1st (of course) doesn't.
Therefore I've specified includePaths
of sass via the riot compiler options. Afterwards the 1st import works but now the 2nd import doesn't work anymore :/
I've found out the problem is your _mixobj
util that is used in the scss parser
https://github.com/riot/compiler/blob/master/lib/parsers/scss.js#L22
It doesn't merge the options deeply what makes it impossible to just extend the existing includePaths
array.
I'll try to fix it and will submit a PR if successful.
Thanks for your patch but have you thought that for your edge case you might just use a custom compilation setup, or simply override the scss preprocessor?
const compiler = require('riot-compiler')
compiler.parsers.css.scss = (tag, css, opts, url) => {
// do your stuff here
}
but have you thought that for your edge case you might just use a custom compilation setup, or simply override the scss preprocessor?
I'm not using the compiler but gulp-riot (that internally uses the compiler).
Therefore I can't override the parsers what btw wouldn't feel as a clean solution – the options merge should be smarter imo than just replacing.
Have you taken a look at my PR?
Yes your PR complicates a lot that part of the compiler source code reducing also the code coverage.
What you are trying to achieve can be solved in 3 lines of code:
import gulp from 'gulp'
import riot from 'gulp-riot'
import compiler from 'riot-compiler'
// the only thing you need to change in your source code is this:
compiler.parsers.css.scss = (tag, css, opts, url) => {
// do your custom scss stuff here
}
gulp.task('riot', ()=> {
gulp.src('example.tag')
.pipe(riot())
.pipe(gulp.dest('dest'))
})
nope, doesn't work :/
My overridden scss parser survives only until this line
https://github.com/riot/compiler/blob/master/lib/compiler.js#L531
Then parsers.req()
overrides it with the default parser and I don't see a way to prevent this or adjust the used REQPATH
.
However I've now worked over the config of my gulp setup so I'm able to add the tag's directory in the custom includePaths
myself (solves my problem).
Thus I'm closing this issue although I still think a bit more complexity in _mixobj
would be reasonable.
if you will post a demo repo example I will try to help you