Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Mix #53

Open
hectorsevillasandoval opened this issue Nov 16, 2020 · 3 comments
Open

Laravel Mix #53

hectorsevillasandoval opened this issue Nov 16, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@hectorsevillasandoval
Copy link

Is it possible to use this plugin with Laravel Mix?

@SassNinja
Copy link
Owner

Hi @barcadictni

thanks for your issue

I haven't worked with Laravel Mix yet, however according to what I read it seems similar to Symfony's Encore which is working (example)

So theoretically I should work but as usual: try and error 😉
(a PR which adds an appropriate example is welcome)

@SassNinja SassNinja added the documentation Improvements or additions to documentation label Jan 22, 2021
@rubenmeines
Copy link

rubenmeines commented Jul 14, 2021

Hey @barcadictni , after 2 days of messing around I found something that helped me out. My objective is just to extract media queries to make a heavy style.css a bit lighter. I am no expert in laravel mix or webpack so I can't guarantee you this is the correct way of doing it, but here is the code from my setup:

let mix = require('laravel-mix');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MediaQueryPlugin = require('media-query-plugin');

mix.options({ 
  processCssUrls: false
});

mix.webpackConfig({
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',                
        ]
      },
      {
        test: /\.scss$/,
        use: [
          MediaQueryPlugin.loader,
          'postcss-loader',
          'sass-loader'             
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin(),
    new MediaQueryPlugin({
      include: true,
      queries: {
        'screen and (max-width: 767px)': '767',
        'screen and (max-width: 1023px)': '1023',
        'screen and (max-width: 1279px)': '1279',
        'screen and (max-width: 1365px)': '1365',
        'screen and (max-width: 1439px)': '1439',
      }
    })
  ]
});

mix.js('src/js/app.js', 'js/app.min.js')
   .sass('src/sass/styles.scss', 'style.css');

This results in this file for example (which is not ideal):

Screenshot 2021-07-14 at 14 10 01

Does anyone know how to combine these media queries so that it is just:
@media screen and (max-width: 767px){ // ALL THE CODE / CLASSES HERE }

?

@rubenmeines
Copy link

rubenmeines commented Jul 14, 2021

I found out how to do it with this package from current owner: https://github.com/SassNinja/postcss-combine-media-query

Just:

  1. Install the package from the link above
  2. create a file named 'postcss.config.js' in root folder where you have webpack.mix.js
  3. Paste this code in postcss.config.js:
module.exports = {
  plugins: [
    require('postcss-combine-media-query')    
  ]
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants