hakhsin's avatar

How can I store all scss file that I import to js/vue files into a css file?

Hi, I want to all scss files that I import to may vue files store in a css file. How can I do it? I am using laravel v6. My laravel resources app structure is like this:

  • resources
    • vuesin
      • components
        • Tree
          • _tree.scss
          • Tree.vue
          • ...

and in Tree.vue I do:

...

<script>
    import './_tree.scss';
    ...
</script>

Every thing work good. But I don't know how to config my laravel mix to store all scss file of components to a *.css file.

0 likes
2 replies
hakhsin's avatar

I found this plugin: MiniCssExtractPlugin. Now, how can I use it in laravel mix?

This is my webpack.mix:

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

const tailwindcss = require('tailwindcss');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/packets/app/app.js', 'public/js')
    .sass('resources/packets/app/styles/scss/app.scss', 'public/css', {}, [
        tailwindcss('./resources/packets/app/styles/tailwind.config.js'),
    ])
    .js('resources/packets/pimosin/pimosin.js', 'public/js')
    .sass('resources/packets/pimosin/styles/scss/pimosin.scss', 'public/css', {}, [
        tailwindcss('./resources/packets/pimosin/styles/tailwind.config.js'),
    ])
    .webpackConfig({
        output: {
            chunkFilename: 'js/chunks/[name].js',
        },
    })
    .options({
        processCssUrls: false,
    });
hakhsin's avatar
hakhsin
OP
Best Answer
Level 6

I found my answer here. This is my webpack.mix.js:

mix.js('resources/packets/app/app.js', 'public/dist')
    .js('resources/packets/pimosin/pimosin.js', 'public/dist')
    .webpackConfig({
        output: {
            chunkFilename: 'dist/chunks/[name].[chunkhash].js'
        },
    })
    .options({
        processCssUrls: false,
        extractVueStyles: '[name].css',
        globalVueStyles: './resources/packets/global-vue-styles.scss',
        postCss: [
            tailwindcss('./resources/packets/tailwind.config.js'),
        ]
    });

Please or to participate in this conversation.