From 82ff437a89dc5c7778c87ad4754953ff5e6c5b30 Mon Sep 17 00:00:00 2001 From: JJ Behrens Date: Thu, 19 Apr 2018 12:33:33 -0700 Subject: [PATCH] Ignore weird Webpack imports that start with `!` --- src/index.js | 5 +++++ .../ignores special webpack imports/actual.js | 7 +++++++ .../ignores special webpack imports/bar.css | 1 + .../ignores special webpack imports/expected.js | 7 +++++++ .../ignores special webpack imports/options.json | 10 ++++++++++ 5 files changed, 30 insertions(+) create mode 100644 test/fixtures/react-css-modules/ignores special webpack imports/actual.js create mode 100644 test/fixtures/react-css-modules/ignores special webpack imports/bar.css create mode 100644 test/fixtures/react-css-modules/ignores special webpack imports/expected.js create mode 100644 test/fixtures/react-css-modules/ignores special webpack imports/options.json diff --git a/src/index.js b/src/index.js index 2c32aa8..33cb227 100644 --- a/src/index.js +++ b/src/index.js @@ -130,6 +130,11 @@ export default ({ return true; } + // Ignore weird Webpack imports that start with `!`. + if (path.node.source.value.startsWith('!')) { + return true; + } + if (stats.opts.exclude && getTargetResourcePath(path, stats).match(new RegExp(stats.opts.exclude))) { return true; } diff --git a/test/fixtures/react-css-modules/ignores special webpack imports/actual.js b/test/fixtures/react-css-modules/ignores special webpack imports/actual.js new file mode 100644 index 0000000..8a4e4c5 --- /dev/null +++ b/test/fixtures/react-css-modules/ignores special webpack imports/actual.js @@ -0,0 +1,7 @@ +import './bar.css'; + +// It should just completely ignore weird imports such as these. +import icomoonCss from '!!raw!./icomoon.global.css'; +import themeVariables from '!less-vars!./variables.global.css'; + +
; diff --git a/test/fixtures/react-css-modules/ignores special webpack imports/bar.css b/test/fixtures/react-css-modules/ignores special webpack imports/bar.css new file mode 100644 index 0000000..5512dae --- /dev/null +++ b/test/fixtures/react-css-modules/ignores special webpack imports/bar.css @@ -0,0 +1 @@ +.a {} diff --git a/test/fixtures/react-css-modules/ignores special webpack imports/expected.js b/test/fixtures/react-css-modules/ignores special webpack imports/expected.js new file mode 100644 index 0000000..60dc7da --- /dev/null +++ b/test/fixtures/react-css-modules/ignores special webpack imports/expected.js @@ -0,0 +1,7 @@ +import './bar.css'; + +// It should just completely ignore weird imports such as these. +import icomoonCss from '!!raw!./icomoon.global.css'; +import themeVariables from '!less-vars!./variables.global.css'; + +
; diff --git a/test/fixtures/react-css-modules/ignores special webpack imports/options.json b/test/fixtures/react-css-modules/ignores special webpack imports/options.json new file mode 100644 index 0000000..6f54db7 --- /dev/null +++ b/test/fixtures/react-css-modules/ignores special webpack imports/options.json @@ -0,0 +1,10 @@ +{ + "plugins": [ + [ + "../../../../src", + { + "generateScopedName": "[name]__[local]" + } + ] + ] +}