Skip to content

Configuring sass-resources-loader using Rails/Webpacker #76

@unikitty37

Description

@unikitty37

I have tried multiple ways to include a variables.scss file in a Rails 5.2.1/VueJS/Webpacker project, with no joy. This is what I have for my webpack/loaders/sass-resources-loader.js:

environment.loaders.get('vue').use[0].options.loaders = {
  scss: [
    'vue-style-loader',
    'css-loader',
    'sass-loader',
    {
      loader: 'sass-resources-loader',
      options: {
        resources: [
          path.resolve(__dirname, 'app', 'javascript', 'variables.scss'),
        ],
      },
    },
  ],
}

but the Vue component that references a variable defined in variables.scss fails to compile with a message Undefined variable: "$header-background-colour".

I've tried various other means of specifying the path:

  • variables.scss
  • javascript/variables.scss
  • app/javascript/variables.scss
  • ../app/javascript/variables.scss
  • ../../app/javascript/variables.scss
  • ../../../app/javascript/variables.scss

All fail.

Currently I have to manually @import 'variables.scss'; into every component, which is not ideal. What is the correct way to specifying the path <rails root>/app/javascript/variables.scss? I'd be happy to add a PR to the docs to give an example of configuring for Rails once I've worked it out :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions