Skip to content

Add sass-resources-loader type functionality for loading SASS filesย #297

@mikeb-meq

Description

@mikeb-meq

Is your feature request related to a problem? Please describe.

I have set up jest-preview in my project and it seems to work well other than loading my styles (with SASS). When I add the following config to my jest.config.js, my test starts encountering "Undefined variable."

module.exports = {
    transform: {
        "^.+\\.(css|scss)$": "jest-preview/transforms/css",

This is happening because I use global SASS variables defined in separate files, and load those using sass-resources-loader with webpack for when the application runs. I found the existing option for globally loading css, but that seems to load the files individually rather than prepending them to all imported scss like sass-resources-loader does.

Describe the solution you'd like

Ideally adding a config option for prepending a set of scss files to all imported scss, like sass-resources-loader supports.

Describe how should jest-preview implements this feature

This could be potentially implemented by reading the contents of the global files and concatenating them with each imported scss using sass.compileString rather than sass.compile, but I don't know how efficient that would be.

Describe alternatives you've considered

I couldn't think of any alternatives that wouldn't require changing application code as a workaround.

I would be happy to try contributing this feature if I could be pointed to the best place to start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions