Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to @import absolute path directly? #2281

Closed
qingmingsang opened this issue Mar 6, 2017 · 5 comments
Closed

How to @import absolute path directly? #2281

qingmingsang opened this issue Mar 6, 2017 · 5 comments

Comments

@qingmingsang
Copy link

webpack

    resolve: {
        alias: {
            $variables: path.resolve('./styles/variables.styl')
        }
    }

xx.styl

@import  '$variables '

//error

How to @import absolute path directly?

@qingmingsang qingmingsang changed the title How to import 'alias path' file? How to @import absolute path directly? Mar 6, 2017
@Panya
Copy link
Member

Panya commented Mar 6, 2017

You should define a variable using define in stylus-loader options:

stylus: {
  define: {
    $variables: path.resolve('./styles/variables.styl')
  }
}

And then inside a stylus file:

@import $variables

You can also use import option to auto-import these variables:

stylus: {
  import: [
    path.resolve('./styles/variables.styl')
  ]
}

@Panya Panya closed this as completed Mar 6, 2017
@qingmingsang
Copy link
Author

qingmingsang commented Mar 7, 2017

@Panya thx,that's very helpful

@shammellee
Copy link
Contributor

@Panya can you point me to documentation for define in your example? Is this a webpack or stylus property?

@Panya
Copy link
Member

Panya commented Mar 26, 2018

It's not documented(?) property of the stylus-loader options object. It corresponds to define method of the stylus JS API (see http://stylus-lang.com/docs/js.html#definename-node). See https://github.com/shama/stylus-loader/blob/master/index.js#L77-L81

@aseem2625
Copy link

aseem2625 commented Jun 8, 2019

In case someone is looking for rollup. globals key is used to define in the plugin rollup-plugin-stylus-compiler

stylus({
   compiler: {
     globals: { $vars: path.resolve('src/styles/_vars.styl') }
   }
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants