linkedin / css-blocks

High performance, maintainable stylesheets.
http://css-blocks.com/
BSD 2-Clause "Simplified" License
6.34k stars 152 forks source link

Productize Eyeglass support #398

Closed chriseppstein closed 4 years ago

chriseppstein commented 4 years ago

Right now we're doing this in css-blocks.config.js to add eyeglass support to a project:

const sass = require("node-sass");
const eyeglass = require("eyeglass");
function scss(file, data, _configuration, _sourceMap) {
  return new Promise((resolve, reject) => {
    const sassOptions = {
      file,
      data,
      outputStyle: "expanded",
      sourceMap: true,
      outFile: file.replace(/scss$/, "css"),
    };
    sass.render(eyeglass(sassOptions), (err, res) => {
      if (err) {
        reject(err)
      } else {
        resolve({
          content: res.css.toString(),
          sourceMap: res.map.toString(),
          dependencies: res.includedFiles,
        })
      }
    });
  })
}
module.exports = {
  preprocessors: { scss }
};

Instead we should be able to do this:

const sass = require("node-sass");
const eyeglass = require("eyeglass");
const eyeglassAdaptor = require("@css-blocks/eyeglass");

const sassOptions = {
  outputStyle: "expanded",
};

const scss = eyeglassAdaptor(sass, eyeglass, sassOptions);

module.exports = {
  preprocessors: { scss }
};

A few things to note here: Sass and Eyeglass are dependency injected. I don't want us to manage what versions or implementations get installed.

The options other than outputStyle that we're setting need to be set that way, we shouldn't allow them to be overridden by the caller so we should Object.assign into their options, not the other way around.

abritinthebay commented 4 years ago

Thanks for the note about the options part. Easy to miss that.

chriseppstein commented 4 years ago

To test this, we can use the mock importer that we use elsewhere in the project with the scss preprocessor configured as above.