Quantcast
Channel: Tips – Bjeld
Viewing all articles
Browse latest Browse all 11

Quick-fix for enabling Decorators with Create-React-App without Ejecting

$
0
0

In my post about using MobX in ReactJS to enable runtime style changes, I Ejected the Create-React-App in order to configure Webpack to enable Decorators, which Im using together with MobX. I found out that I could Quick-fix this without Ejecting.

Disclaimer: Im using the latest Create-React-App version; time of writing, this is version “react-scripts”: “0.6.1”

First of all you need to “npm install babel-plugin-transform-decorators-legacy –save”

After that is done, find these to configuration files:

  1. node_modules/react-scripts/config/webpack.config.dev.js
  2. node_modules/react-scripts/config/webpack.config.prod.js

 

webpack-dev-prod-config

 

 

 

 

 

 

 

 

With those 2 files open you need to add this line plugins: [‘transform-decorators-legacy’ ]

Have a look at these screenshots to find out where you must put them.

In webpack.config.dev.js
dev-add-decorator

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In webpack.config.prod.js
prod-add-decorator

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

With those in place you should be able to use Decorators in your Create-React-App.


Viewing all articles
Browse latest Browse all 11

Trending Articles