Comments (4)
@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 }
}
}
}),
- Now, we can patch
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)
}
This dirty solution works as a workaround and should definitely be addressed in other way. Although, it works cleanly enough not to relay on any dirty patch located in 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 }
}
}
}),
]
🚀
from component-compiler-utils.
@y-nk You rock, man! It works well!
from component-compiler-utils.
this is the most problematic in rollup-plugin-vue
for me, have you find a way for this issue ?
from component-compiler-utils.
it looks like rollup-plugin-vue
does not support alias resolution in style blocks... how come this is not solved yet ?
from component-compiler-utils.
Related Issues (20)
- Clarification request about scoped style
- https://www.npmjs.com/advisories/1693
- with newes component-compiler-utils @3.2.2 , error
- Update postcss HOT 9
- Add License File
- Hash collision with `hash-sum` package
- Problem with `prettier@3` HOT 2
- [Feature Request] Bump prettier to version 3
- [Question] Less imports @import '~@pkg/path/to/stylesheet.less'
- CVE-2023-44270 on package dependencies HOT 7
- TypeError: Cannot read property 'parseComponent' of undefined HOT 32
- Switch `prettier` to an optional- or peerDependency HOT 2
- :root Selector should not be scoped HOT 1
- typescript definition for SFCDescriptor isn't compatible with vue-template-compiler HOT 1
- npm ERR! 404 '@vue/component-compiler-utils@latest' is not in the npm registry. HOT 2
- Typo on README
- Cannot read property 'parseComponent' of undefined
- optionalDependencies are installed as normal dependencies HOT 4
- About debugging components defined by the same name HOT 1
- About adding a firstChar('@') in the templateCompilerModules/utils
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from component-compiler-utils.