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

Is there a Parcel equivalent to Webpack's resourceQuery? #2186

Closed
EmilTholin opened this issue Oct 23, 2018 · 1 comment
Closed

Is there a Parcel equivalent to Webpack's resourceQuery? #2186

EmilTholin opened this issue Oct 23, 2018 · 1 comment

Comments

@EmilTholin
Copy link

EmilTholin commented Oct 23, 2018

❔ Question

Is there a Parcel equivalent to Webpack's resourceQuery that allows you to use different loaders for assets with the same file extension with the help of a query parameter, or something similar?

🔦 Context

Parcel is a phenomenal tool, and the only thing that is holding me back from migrating to it in various projects is that there seems to be no way to treat assets with the same extension in different ways. This applies to e.g. loading some CSS as global and some as CSS modules, some images as regular images and some as lqip previews, etc.

💻 Code Sample

In Webpack you can use a resourceQuery to e.g. treat imported CSS with an added ?global query parameter as regular global CSS, and every other CSS file as CSS modules.

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /.css$/,
        oneOf: [
          {
            // Use e.g. import 'react-select/dist/react-select.css?global'
            // to treat the CSS as global
            resourceQuery: /global/, 
            use: ['style-loader', 'css-loader']
          },
          {
            // All other files will be treated as CSS modules
            use: ['style-loader', 'css-loader'],
            options: {
              modules: true,
              localIdentName: '[name]__[local]_[hash:base64:5]'
            }
          }
        ]
      }
    ]
  }
};
@mischnic
Copy link
Member

Currently not (and there are other usecases where this is really needed), merging with #1084

Parcel 2 might process name.module.css files as modules and others as "starndard" CSS files, which is also how CRA handles this.

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

No branches or pull requests

3 participants