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 do I inject data from JS files into stylus? #221

Closed
eliot-ye opened this issue Jul 8, 2019 · 2 comments · Fixed by #248
Closed

How do I inject data from JS files into stylus? #221

eliot-ye opened this issue Jul 8, 2019 · 2 comments · Fixed by #248

Comments

@eliot-ye
Copy link

eliot-ye commented Jul 8, 2019

if i has a js:

module.exports = {
  textColor: "#333"
}

How do I inject this data into stylus? Like the "data" field of the SCSS configuration:

const styleVariables = require('/style/scss/variables')
{
  test: /\.scss$/,
  use: [
    'css-loader',
    'postcss-loader',
    {
      loader: 'sass-loader',
      options: {
        data: Object.keys(styleVariables)
          .map(k => `\$${k}: ${styleVariables[k]};`)
          .join('\n')
      }
    }
  ]
}
a {
  color: $textColor;
}
@niilshyika
Copy link

Hello!
You can use json(...) function in stylus http://stylus-lang.com/docs/bifs.html#jsonpath-options
Before you should convert .js to .json

@alexander-akait
Copy link
Member

You can use json #199, also we will implement the additionalData option

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

Successfully merging a pull request may close this issue.

3 participants