How can I import scss into my Vue components?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Mastering SCSS Imports in Vue Components: Solving Webpack Alias Headaches

As a senior developer working with the Laravel and Vue ecosystem, path resolution and asset management often become points of friction. You are attempting to import your global SCSS file within a <style lang="scss"> block in a Vue component, but you run into errors like "sass is not recognized," even after setting up aliases in webpack.mix.js. This is a common hurdle that stems from the difference between how build tools resolve paths for compilation versus how runtime environments (like Vue SFCs) expect those references to be handled.

This post will dive deep into why your alias setup might be failing and provide the most robust, practical solutions for importing SCSS correctly in your Vue application.


Understanding the Conflict: Build Aliases vs. Component Imports

The core issue you are facing is a conflict between the file system path resolution defined in Webpack (via webpack.mix.js) and how the Sass compiler processes @import directives within a Single File Component (SFC).

When you define an alias like 'sass': path.resolve(__dirname, '/resources/assets/sass'), you are telling Webpack where to find the source files during the bundling process. However, when you write @import 'sass/app.scss'; inside a component style block, Sass expects that reference to resolve relative to the compiled output or the specific context of that file, which can be tricky when dealing with global asset imports managed by Mix.

The error typically means that the compiler cannot find the referenced file at runtime, even if Webpack successfully bundled it.

Solution 1: Managing Global Styles via Mix (The Recommended Approach)

For global styles that affect the entire application (like variables or base resets), the best practice is to let Laravel Mix handle the compilation and injection of these files into your main CSS bundle, rather than trying to import them directly inside every component.

In your webpack.mix.js, ensure your asset compilation is clean:

javascript
const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css'); // This compiles the global styles into a single CSS file

After running npm run dev or npm run watch, Mix compiles app.scss into your public CSS, which is then linked in your main HTML entry point (e.g., index.html). This ensures that all global styles are loaded once and correctly at the application level, adhering to solid architectural principles seen in modern Laravel setups.

Solution 2: Importing Specific Styles within Vue Components

If you need component-specific styling, you should treat those styles as local assets directly related to the component file. Avoid trying to import large global SCSS files into every .vue file.

Instead of using @import, use standard CSS/SCSS nesting or direct class application:

vue
<template>
  <div class="my-component">
    Hello World
  </div>
</template>

<style lang="scss" scoped>
  /* Define component-specific styles here */
  .my-component {
    margin: 0;
    padding: 15px;
    background-color: #f0f0f0; /* Use direct values or variables defined locally */
  }
</style>

If you absolutely must pull in a specific utility file, reference it relative to the component's location or use standard CSS @import rules that are guaranteed to resolve within the context of the emitted CSS.

Solution