gajus / gajus/babel-plugin-react-css-modules

`exclude` won't work with `require.context`

オープン
#65 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
JavaScript
スター
2k
フォーク
159
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi,

I'll try to open a PR if I get no where, but I'd like to exclude a file from being transformed, but that file is required via `require.context`. when debugging, here is the output of `stats` when it tries to go over the file (config.js) that uses `require.context`:

```
PluginPass {
_c: Map {},
dynamicData: {},
plugin:
Plugin {
_c: Map {},
dynamicData: {},
initialized: true,
raw: {},
key: 'react-css-modules',
manipulateOptions: [Function: manipulateOptions],
post: undefined,
pre: undefined,
visitor:
{ _exploded: {},
_verified: {},
ImportDeclaration: [Object],
JSXElement: [Object],
Program: [Object] } },
key: 'react-css-modules',
file:
File {
_c: Map {},
dynamicData: {},
pipeline: Pipeline {},
log:
Logger {
filename: '/Users/mshertzberg/Gizmodo/kinja-components/.storybook/config.js',
file: [Circular] },
opts:
{ filename: '/Users/mshertzberg/Gizmodo/kinja-components/.storybook/config.js',
filenameRelative: '/Users/mshertzberg/Gizmodo/kinja-components/.storybook/config.js',
inputSourceMap: undefined,
env: [Object],
mode: undefined,
retainLines: false,
highlightCode: true,
suppressDeprecationMessages: false,
presets: [],
plugins: [Object],
ignore: [],
only: undefined,
code: true,
metadata: true,
ast: true,
extends: undefined,
comments: true,
shouldPrintComment: undefined,
wrapPluginVisitorMethod: undefined,
compact: 'auto',
minified: false,
sourceMap: false,
sourceMaps: false,
sourceMapTarget: 'config.js',
sourceFileName: '.storybook/config.js',
sourceRoot: '/Users/mshertzberg/Gizmodo/kinja-components',
babelrc: false,
sourceType: 'module',
auxiliaryCommentBefore: undefined,
auxiliaryCommentAfter: undefined,
resolveModuleSource: undefined,
getModuleId: undefined,
moduleRoot: '/Users/mshertzberg/Gizmodo/kinja-components',
moduleIds: false,
moduleId: undefined,
passPerPreset: false,
parserOpts: false,
generatorOpts: false,
basename: 'config' },
parserOpts:
{ sourceType: 'module',
sourceFileName: '/Users/mshertzberg/Gizmodo/kinja-components/.storybook/config.js',
plugins: [Object] },
pluginVisitors: [ [Object] ],
pluginPasses: [ [Object] ],
metadata: { usedHelpers: [], marked: [], modules: [Object] },
dynamicImportTypes: {},
dynamicImportIds: {},
dynamicImports: [],
declarations: {},
usedHelpers: {},
path:
NodePath {
parent: [Object],
hub: [Object],
contexts: [Object],
data: {},
shouldSkip: false,
shouldStop: false,
removed: false,
state: undefined,
opts: [Object],
skipKeys: {},
parentPath: null,
context: [Object],
container: [Object],
listKey: undefined,
inList: false,
parentKey: 'program',
key: 'program',
node: [Object],
scope: [Object],
type: 'Program',
typeAnnotation: null },
ast:
Node {
type: 'File',
start: 0,
end: 722,
loc: [Object],
program: [Object],
comments: [],
tokens: [Object] },
code: 'import \'preact/devtools\';\nimport {\n\tconfigure,\n\taddDecorator,\n\twithCentered,\n\twithKnobs,\n\tsetOptions\n} from \'../config/storybook\';\nimport { StyletronHOC } from \'../config/styletron\';\n\nfunction loadStories() {\n\tconst req = require.context(\'../components\', true, /story.js$/);\n\treq.keys().forEach(filename => req(filename));\n}\n\naddDecorator(getStory => {getStory()});\naddDecorator(withCentered);\naddDecorator(withKnobs);\n\nsetOptions({\n\tname: \'kinja-components\',\n\turl: \'https://github.com/gawkermedia/kinja-components\',\n\tgoFullScreen: false,\n\tshowLeftPanel: true,\n\tshowDownPanel: true,\n\tshowSearchBox: false,\n\tdownPanelInRight: true,\n\tsortStoriesByKind: true\n});\n\nconfigure(loadStories, module);\n',
shebang: '',
hub: Hub { file: [Circular], options: undefined },
scope:
Scope {
uid: 16,
parent: null,
hub: [Object],
parentBlock: [Object],
block: [Object],
path: [Object],
labels: [Object],
references: [Object],
bindings: [Object],
globals: [Object],
uids: {},
data: {},
crawling: false } },
opts:
{ generateScopedName: '[hash:base64:10]',
webpackHotModuleReloading: true,
exclude: 'story',
filetypes: { '.scss': 'postcss-scss' } } }
```

I would imagine this requires a PR to implement?

Thanks.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

.storybook/config.js から問題を再現し、require.context の呼び出しと、示されている exclude オプションに注目してください。そのコンテキストを通じてファイルが読み込まれる際に、除外がどのように適用されるかを調べてください。意図した除外対象のファイルが変換されず、他のコンテキスト経由で読み込まれたファイルは引き続き動作すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
32/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。