question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sass not loading from Vue component when compiling with Laravel Mix

See original GitHub issue
  • Laravel Mix Version: 6.0.11
  • Node Version (node -v): 14.15.4
  • NPM Version (npm -v): 6.14.9
  • webpack: 5.19.0
  • webpack-cli: 4.4.0
  • webpack-dev-server: 4.0.0-beta.0
  • OS: Fedora 33

Description:

Hi everyone,

Upgraded to Laravel Mix 6 & Webpack 5 and have a problem with compiling. It finishes successfully but not including styles imported from withing Vue component. Specifically, I’m using Vue Splide adapter to display the slider on my main page and styling is broken.

I’m including styles like this:

// Slider component...
<style lang="scss">
    @import '~@splidejs/splide/dist/css/themes/splide-default.min.css';
</style>
// webpack.mix.js
mix.sass('resources/sass/app.scss', 'public/front/css')
   .js('resources/js/app.js', '')
   .vue()
   .alias({
     ziggy: path.resolve('vendor/tightenco/ziggy/src/js/route.js'),
     '@components': path.resolve(__dirname, 'resources/js/Components'),
     '@publicDir': path.resolve(__dirname, 'public')
   })
   .webpackConfig(config)
   .mergeManifest()
   .options({
     extractVueStyles: true,
   })
   .extract();

I tried without .options() also & still styles not included. But if I move @import '~@splidejs/splide/dist/css/themes/splide-default.min.css'; to app.scss slider styles are included.

I only need slider styles within the Slider component so it doesn’t make sense for move styles to app.scss.

This thing was working on Mixv5/WP4.

Am I missing something?

P.S. I’ve also modified .vue() with:

.vue({
    extractStyles: true,
})

But in this case, app tries to load app.js with app.js?id=[chunkhash] which is equal to front0.js?id=[chunkhash] and I’m getting error loading chunk file.

I do see that app.css file is slightly bigger in this case, which means that slider styles are included there from vue component <style>

Original post: https://laracasts.com/discuss/channels/elixir/sass-not-loading-from-vue-component-when-compiling-with-laravel-mix

Steps To Reproduce:

Include sass/scss style from the Vue component and see if it’s compiled.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
beaubuscommented, May 18, 2021

Hey @beaubus Did you figure out how to fix the globalStyles issue?

No, it was faster for me at that moment to just convert globalStyles to local styles.

0reactions
kranthiboga23commented, Oct 10, 2022

@mdsaifurrahmann please refer following image, if i remove extractStyles/extractVueStyles. CSS is loading from .vue file(not optimizing - not loading from app.css) - but wokring as excepted vue

If i keep extractStyles/extractVueStyles. CSS is loading from minified file app.css but not extracting CSS/SCSS from .vue files into app.css

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass not loading from Vue component when compiling with ...
Hi everyone,. Upgraded to Laravel Mix 6 & Webpack 5 and have a problem with compiling. It finishes successfully but not including styles ......
Read more >
Sass not loading from Vue component when ... - Laracasts
Hi everyone, Just upgraded to Laravel Mix 6 & Webpack 5 and have a problem with compiling. It finishes successfully but not including...
Read more >
Vue components can't use scss in laravel - Stack Overflow
I was able to solve this by following this in the documentation: https://laravel-mix.com/docs/4.0/upgrade#vue-component-sass-preprocessing.
Read more >
Using SASS in Vue Components with Laravel Mix
It's a little tricky using SASS in Vue Components when compiled with Laravel Mix, in this tutorial we will go into how to...
Read more >
Sass Preprocessing | Laravel Mix Documentation
Let's add Sass compilation to our webpack.mix.js file. ... Laravel Mix of course defers to webpack's sass-loader to load and compile your Sass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found