Comments (16)
So, the end of the story is, the "react-app-rewired approach" is to use .babelrc like explained in this issue:
timarney/react-app-rewired#328
I'd say it's a viable solution, let's close this.
from customize-cra.
I think it should address the changes in this file as well:
from customize-cra.
Sorry - no clue why that's not working. Hopefully someone can chime in with some advice
from customize-cra.
Can you reproduce at least? Just to understand if I'm doing something wrong or if it's a bug.
from customize-cra.
I’ve never used emotion, sorry
from customize-cra.
the problem should be reproducible with any babel plugin, not just emotion.
from customize-cra.
No idea, sorry. I'm already using the add babel plugin for decorators, so that should work fine. Not sure why this isn't working.
You'll need to debug, and feel free to send a PR when you find what's wrong.
from customize-cra.
I'm digging into it, I don't quite get how can it currently work considering that the Babel configuration for webpack is generated at runtime and the one of the Jest transformer for JS is read from the file I linked above 🤔
from customize-cra.
I assume you've npm installed the actual plugin? Assuming you have, no idea what the problem might be.
from customize-cra.
Yes it's installed, I'm now trying with a random plugin (currently trying babel-plugin-trace
) and see if it fails with that as well.
from customize-cra.
Here is a repro:
https://github.com/FezVrasta/customize-cra-bug-repro-babel-plugin
when you do yarn start
you see two logs in the console. When you run yarn test
just one (because the babel-plugin-trace
is not being injected for some reason)
from customize-cra.
Ohhhhhh - test. I see now - so config-overrides isn't being hit when you run npm test
as opposed to npm start
.
If @timarney has a second, maybe he can chime in.
from customize-cra.
The title now is a bit misleading, is not that it's not being processed in "test command", that's expected because by default create-app-rewired will use the function exported by config-overrides only for webpack, you have to do this to also override jest:
module.exports = {
webpack: override(addBabelPlugin('babel-plugin-trace')),
jest: override(somethingElse()),
}
But the problem is that addBabelPlugin
doesn't actually work when used in the jest
field, because it expects the webpack config while actually the Jest config is provided.
Now, we could provide an addBabelPluginToTests
, but the problem is that we can't easily do that because Jest expects a file as transformer rather than a javascript function, so we'd have to create a file at runtime or something like that...
to explain, CRA provides as transformer this file.
The Jest config is like this:
transform: {
'^.+\\.(js|jsx)$': 'node_modules/react-scripts/config/jest/babelTransform.js',
edit:
we could provide our own babelTransform.js
that internally reads the Webpack babel configuration of CRA and applies the needed config-overrides.js logic to it?
const babelJest = require('babel-jest');
const overrides = require('../config-overrides');
const webpackConfigPath = paths.scriptVersion + "/config/webpack.config.dev";
const webpackConfig = require(webpackConfigPath);
overrides.webpack(webpackConfig, process.env.NODE_ENV);
const babelLoaderFilter = rule => rule.loader && rule.loader.includes("babel") && rule.options && rule.options.plugins;
let loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf;
let babelLoader = loaders.find(babelLoaderFilter);
// If the loader was not found, try to find it inside of the "use" array, within the rules.
// This should work when dealing with [email protected].* versions.
if (!babelLoader) {
loaders = loaders.reduce((ldrs, rule) => ldrs.concat(rule.use || []), []);
babelLoader = loaders.find(babelLoaderFilter);
}
module.exports = babelJest.createTransformer(babelLoader.options);
I doubt this one above is working but I hope it gives the idea.
from customize-cra.
Update:
actually, I just noticed that react-app-rewired already overrides the babelTransform.js
file with its own modified version that adds support for the babel-plugin-transform-decorators-legacy
(and this explains why they work for @arackaf)
but I don't understand how we are supposed to hook into it and add our own stuff...
from customize-cra.
So sorry I couldn't understand / be more of a help here. Thanks a ton for the PRs!
from customize-cra.
Hey, @FezVrasta
npm test works if you create a .babelrc with mentioned settings but do you know how to get breakpoints working for debugging tests?
from customize-cra.
Related Issues (20)
- __webpack_require__(...) is not a function
- CRA v4 switch from GenerateSW to InjectManifest not supported - workaround
- Is this project unmaintained? anybody here? HOT 1
- Example of "addWebpackExternals" has a error HOT 1
- 啥时候更新webpack5
- how can I prevent build/service-worker.js from being generated. I don't want any caching. please help, urgent
- add graphql loader
- create-react-app 强制更新到了 5.0.0 ,启用的是 webpack5,在配置 less 的时候出现错误 postcss Loader has been initialized using an options object that does not match the API schema,影响项目开展,望修复 HOT 12
- Incompatible with Create-React-App 5.0: Invalid Options for PostCSS Loader HOT 8
- PostCSS plugin autoprefixer requires PostCSS 8.
- options has an unknown property 'plugins' HOT 1
- useEslintRc ERROR!! HOT 1
- addWebpackExternals: react is not defined HOT 2
- Using customizers for jest configuration HOT 3
- addPostcssPlugins doesn't work when react-scripts's version higher than or equal to 5.0.0 HOT 5
- setWebpackPublicPath auto option HOT 1
- Workbox strategies uncaught no-response
- TypeError: addWebpackPlugin is not a function
- react项目:在configoveride.js中addPostcssPlugins添加postcss-pxtorem无效 HOT 7
- getBabelLoader().options is undefined when you fix babel-loader
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from customize-cra.