Giter VIP home page Giter VIP logo

Comments (4)

y-nk avatar y-nk commented on May 3, 2024 10

@KarlBao @r4fx after few hours of debugging, i found a fix which works.

In your rollup config, add :

  1. Import the stylus node evaluator with import { Evaluator } from 'stylus'

  2. Pass it along the vue options with

vue({
  style: {
    preprocessOptions: {
      stylus: { Evaluator }
    }
  }
}),
  1. 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.

KarlBao avatar KarlBao commented on May 3, 2024 1

@y-nk You rock, man! It works well!

from component-compiler-utils.

r4fx avatar r4fx commented on May 3, 2024

this is the most problematic in rollup-plugin-vue for me, have you find a way for this issue ?

from component-compiler-utils.

y-nk avatar y-nk commented on May 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.