Skip to content

Feat/add regexp support for filetype #240

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

Merged
merged 7 commits into from
Sep 17, 2020

Conversation

xuxinhang
Copy link
Contributor

Add supports for using RegExp patterns as key names in filetype

Usage

Now, we can use a RegExp pattern in filetypes to specify a certain file.

Consider the following config.

{
  filetypes: {
    '\\.mod\\.sass$': { syntax: 'sugarss' },
  },
}
// component.js
import './components/another.mod.sass';
import './components/another.sass';

// ... ...

According to the config above, babel-plugin-react-css-modules will match and process another.mod.sass, but live another.sass alone.

Why is this useful?

Sometimes, I want to import some .sass file as global styles (such as styles for the common UI). However, if I just add the key .sass to filetypes, then all imported .sass files would be processed, including those containing global styles. (By the way, I dislike :global.)

The support for RegExp patterns would also be useful when assigning the different plugin lists (or other config items) to the different .sass files.

Compatibility

The all test cases is covered. (yarn test on my computer.)

It is worth discussing further if there are any better implements or API designs.

@gajus gajus merged commit 91c8e9b into gajus:master Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants