简体   繁体   English

React,Webpack,Stylus-将全局变量导入所有组件

[英]React, Webpack, Stylus - import global variables to all components

I have react app and in webpack I have this code: 我有反应的应用程序,并在webpack我有此代码:

stylus: {
    use: [require('nib'), require('jeet')],
    import: [
        '~nib/lib/nib/index.styl',
        '~jeet/stylus/jeet/_jeet',
        '~rupture/rupture/index.styl'
    ]
}

How can I import my variable.styl to every component globally? 如何将我的variable.styl导入全局的每个组件? I need add something like this: 我需要添加如下内容:

stylus: {  
    import: [
        './app/styles/variables.styl'
    ]
}

after this webpack stopped at 96% and nothing else. 在此webpack停止在96%之后,别无其他。

Most paths in the Webpack configuration need to be full paths (absolute, not relative). Webpack配置中的大多数路径都必须是完整路径(绝对路径,不是相对路径)。

Try this: 尝试这个:

const path = require('path');
...
stylus: {  
  import: [
    '~nib/lib/nib/index.styl',
    '~jeet/stylus/jeet/_jeet',
    '~rupture/rupture/index.styl',
    path.resolve(__dirname, './app/styles/variables.styl')
  ]
}

(I think the initial three imports may not be necessary if they also get @import 'ed in variables.styl ). (我认为,如果最初的三个导入也可以在variables.styl @import则可能没有必要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM