Skip to content

feat: respect exclude setting in JSXElement transform #215

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"start": "webpack-dev-server"
},
"dependencies": {
"babel-plugin-react-css-modules": "^2.1.3",
"babel-plugin-react-css-modules": "^4.0.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"webpack": "^2.7.0"
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export default ({
return require.resolve(path.node.source.value);
};

const isFilenameExcluded = (filename, exclude) => {
return filename.match(new RegExp(exclude));
};

const notForPlugin = (path: *, stats: *) => {
stats.opts.filetypes = stats.opts.filetypes || {};

Expand All @@ -130,7 +134,9 @@ export default ({
return true;
}

if (stats.opts.exclude && getTargetResourcePath(path, stats).match(new RegExp(stats.opts.exclude))) {
const filename = getTargetResourcePath(path, stats);

if (stats.opts.exclude && isFilenameExcluded(filename, stats.opts.exclude)) {
return true;
}

Expand Down Expand Up @@ -179,6 +185,10 @@ export default ({
JSXElement (path: *, stats: *): void {
const filename = stats.file.opts.filename;

if (stats.opts.exclude && isFilenameExcluded(filename, stats.opts.exclude)) {
return;
}

let attributeNames = optionsDefaults.attributeNames;

if (stats.opts && stats.opts.attributeNames) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div styleName="missing_import" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
[
"../../../../src",
{
"generateScopedName": "[name]__[local]",
"exclude": "input"
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

<div styleName="missing_import" />;