如果您不想从Create-React-App中弹出,可以使用package.json中的CLI覆盖“transformIgnorePatterns”。
参考 - https://github.com/facebook/create-react-app/issues/2537#issuecomment-390341713
"scripts": {
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!your-module-name)/\"",
},
"transformIgnorePatterns": [
"node_modules/(?!(react-qr-reader)/)"
]
module.exports = {
presets: [
[
"@babel/preset-env",
{
"modules": "commonjs",
"debug": false
}
],
/// your presets
],
plugins: [
//... your plugins
]
};
npx create-react-app myProject
->yarn add react-qr-reader
-> 在 src/App.js 中添加import QRReader from 'react-qr-reader';
-> 运行yarn test
。 - CherryNerd