Open KarlBao opened 6 years ago
this is the most problematic in rollup-plugin-vue
for me, have you find a way for this issue ?
it looks like rollup-plugin-vue
does not support alias resolution in style blocks... how come this is not solved yet ?
@KarlBao @r4fx after few hours of debugging, i found a fix which works.
In your rollup config, add :
Import the stylus node evaluator with import { Evaluator } from 'stylus'
Pass it along the vue
options with
vue({
style: {
preprocessOptions: {
stylus: { Evaluator }
}
}
}),
Evaluator
to support alias resolution :const visitImport = Evaluator.prototype.visitImport
Evaluator.prototype.visitImport = function(imported) {
const path = imported.path.first
if (path.string.startsWith('~'))
path.string = path.string.replace('~', '').replace('@', '/whatever-absolute-path-we-want/src')
return visitImport.call(this, imported)
}
node_modules
.All in one place explanation :
import alias from 'rollup-plugin-alias'
import vue from 'rollup-plugin-vue'
import { Evaluator } from 'stylus'
const aliases = {
'@' : `${__dirname}/src`
}
const visitImport = Evaluator.prototype.visitImport
Evaluator.prototype.visitImport = function(imported) {
const path = imported.path.first
if (path.string.startsWith('~')) {
const alias = Object.keys(aliases).find(entry => path.string.startsWith(`~${entry}`))
if (alias)
path.string = path.string.substr(1).replace(alias, aliases[alias])
}
return visitImport.call(this, imported)
}
const plugins = [
alias(aliases),
vue({
style: {
preprocessOptions: {
stylus: { Evaluator }
}
}
}),
]
🚀
@y-nk You rock, man! It works well!
Expected behavior
Expect to locate the
.styl
file fromnode_modules
with~
(which works well when bundled with Webpack)Actual behavior
Get the error:
However, when I import the
.styl
file with relative path:It works fine.
Steps to reproduce the behavior
My rollup config: