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

'css-loader' options not being applied to extracted media query files #18

Open
robhalkema-pbx opened this issue Jul 25, 2019 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@robhalkema-pbx
Copy link

Hi,

I am trying to incorporate the media-query-plugin into our Webpack build but it is not working as expected, and I'm wondering if there something obvious that I am doing wrong or missing, or if it's a bug?

The problem is with css-loader options not being applied to media query files. Specifically I use the modules option and set localIdentname in css-loader. This works correctly for rules in the non-media query bundle:

.Button__default__1OhNF {
 ...
}

but rules in the extracted media query bundles are not getting modified:

@media screen and (min-width: 960px) {
.container--slim > div {
  ...
}

This is what my config looks like:

plugins: [
    ...
    new MediaQueryPlugin({
      include: true,
      queries: {
        'screen and (min-width: 640px)': 'medium',
        'screen and (min-width: 960px)': 'large',
        'screen and (min-width: 1280px)': 'x-large',
      },
      groups: {
        bundle: /.*/
      },
    }),
    new MiniCssExtractWebpackPlugin(
      {
        filename: '[name].[contenthash].css',
      }
    ),
  ],
  module: {
    rules: [
      {
        test: /\.(scss|css)$/,
        use: [
          MiniCssExtractWebpackPlugin.loader,
          {
            loader: 'css-loader',
            options: {
              modules: {
                localIdentName: isDev ? '[name]__[local]__[hash:base64:5]' : '[hash:base64:5]',
              },
              importLoaders: 2,
            },
          },
          MediaQueryPlugin.loader,
          'postcss-loader',
          'sass-loader',
          {
            loader: 'sass-resources-loader',
            options: {
              resources: getBrandResources(__dirname, brandName),
            },
          },
        ],
      },
    ],
  },

Thanks.

@SassNinja
Copy link
Owner

Hi @robhalkema-pbx

this seems to be related to #17

The problem is no loaders get applied to the generated media chunks.
I've to do some research to find a solution for this.

@SassNinja SassNinja added the bug Something isn't working label Aug 8, 2019
@SassNinja SassNinja added this to the 2.0.0 milestone Aug 8, 2019
@robhalkema-pbx
Copy link
Author

Hi @SassNinja, thanks for the update and for confirming that this is a bug.

As an aside, I also looked at https://github.com/mike-diamond/media-query-splitting-plugin which splits and generates the media query files after the loader has been applied. I needed to rework it a bit, as the configuration doesn't suit a mobile first approach, but it may be a way around the loader issue. I did encounter a problem with our CSS nested in @supports rules not being extracted, and haven't taken it any further.

@ajayjaggi97
Copy link

Hey @SassNinja @robhalkema-pbx any updates on this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants