Vue CLI Style Resources Loader Plugin

0.1.5 · maintenance · verified Sun Apr 19

This package is a Vue CLI plugin designed to simplify the integration of `style-resources-loader` into Vue projects managed by Vue CLI. Its primary function is to automatically inject global style resources, such as Sass variables, Less mixins, or Stylus functions, into all relevant preprocessor files across your project, eliminating the need for repetitive `@import` statements in every component or style block. The current stable version is `v0.1.5`. Release cadence has been irregular, primarily for dependency upgrades. While effective for existing Vue CLI projects, its relevance for new Vue 3 projects is diminishing as the ecosystem shifts towards build tools like Vite, which use different plugin architectures. It acts as a configuration abstraction over `style-resources-loader` itself.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install the plugin using `vue add` and configure global style resource injection in `vue.config.js`. It shows how to automatically make Sass variables and mixins available in all `.scss` files without explicit `@import` statements.

vue add style-resources-loader

// Then, in your vue.config.js file:
const path = require('path')
module.exports = {
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'scss', // or 'sass', 'stylus', 'less'
      patterns: [
        path.resolve(__dirname, './src/styles/abstracts/_variables.scss'),
        path.resolve(__dirname, './src/styles/abstracts/_mixins.scss'),
        path.resolve(__dirname, './src/styles/globals/*.scss')
      ]
    }
  }
}

// Example SCSS file (e.g., src/styles/globals/_variables.scss)
// $primary-color: #42b983;
// $font-stack: Helvetica, sans-serif;

// Example Vue component style block (src/components/HelloWorld.vue)
// <style lang="scss">
//   .hello {
//     color: $primary-color; // $primary-color is automatically available
//     font-family: $font-stack;
//   }
// </style>

view raw JSON →