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

Feature request: allow passing path to sass config file #1

Open
jrencz opened this issue Aug 11, 2017 · 3 comments
Open

Feature request: allow passing path to sass config file #1

jrencz opened this issue Aug 11, 2017 · 3 comments

Comments

@jrencz
Copy link

jrencz commented Aug 11, 2017

First thing: thank you for following my suggestion and starting this project!

My use case:

As I mentioned described in jgranstrom/sass-extract-loader#2 I have custom importers and functions in sass and it's not possible to use this babel plugin without them because of sass errors.
Since babel doesn't allow babelrc.js (babel/babel/issues/4630) and node sass has no option to pass path to options instead of actual options the only way I see is to add options loader in the plugin

@jrencz
Copy link
Author

jrencz commented Aug 11, 2017

I modified the source of plugin but there's an error I can't debug (probably somewhere inside node-sass binding)

My version of extractVariables:

const configs = new Map();

function extractVariables(absolutePath, compiledFiles, options) {
  let vars;
  if(compiledFiles[absolutePath]) {
    vars = compiledFiles[absolutePath];
  } else {
    if ('sassConfigPath' in options && !configs.has(options.sassConfigPath)) {
      configs.set(options.sassConfigPath, require(path.resolve(options.sassConfigPath)));
    }

    const loadedOptions = configs.get(options.sassConfigPath);

    vars = compiledFiles[absolutePath] = sassExtract.renderSync(Object.assign({}, options, loadedOptions, {file: absolutePath})).vars;
  }

  return vars;
}
{
  "plugins": [
    ["babel-plugin-sass-extract", {
      "sassConfigPath": "./sass.conf.js"
    }],
  ]
}

I went down to renderSync in sass-extrct. Code stops at:

var rendered = _nodeSass2.default.renderSync(compileOptions);

Wrapping it in try-catch doesn't help.

@jgranstrom
Copy link
Owner

@jrencz thank you for your contributions. I am currently looking into handling additional custom importers and passing functions through the plugins. The custom importers will initially need some more work in the sass-extract core library. Regarding the function passing issue I might add an alternative configuration method by having a sass-extract.config.js in the working directory of the plugins that can contain the functions.

@jrencz
Copy link
Author

jrencz commented Aug 24, 2017

dedicated file seems reasonable

Going from there to expressing the path in plugin config via .babelrc is not far away

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

No branches or pull requests

2 participants