Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable JIT(Just in time mode) with create react app?

I tried setting up the JIT in create-react-app by myself but it doesn't seem to be working as in the styles are not getting updated. I am using craco to build the app with tailwind css and also added TAILWIND mode=WATCH as they suggested to make it work with most builds . Here are my configs:

tailwind.config.js

module.exports = {
mode: "jit",
purge: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
darkMode: false, // or 'media' or 'class'
theme: {
    extend: {
        colors: {
            primary: "#ffa500",
            secondary: {
                100: "#E2E2D5",
                200: "#888883",
            },
        },
    },
},
variants: {
    extend: {
        opacity: ["disabled"],
    },
},
plugins: [],};

package.json scripts

    "scripts": {
    "start": " craco start",
    "build": "TAILWIND_MODE=watch craco build",
    "test": "craco test",
    "server": "nodemon ./server/server.js",
    "eject": "react-scripts eject"
},

package.json devDependencies

"devDependencies": {
    "autoprefixer": "^9.8.6",
    "postcss": "^7.0.36",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.4"
},

I'll be glad if I could get any way to fix this .

like image 607
Ameya Jangam Avatar asked Aug 02 '21 10:08

Ameya Jangam


People also ask

Does create React app use Git?

Now that you know how to identify a create-react-app, you can use git to pull the project from GitHub. This step entails simply navigating to the project's repository on GitHub, selecting the remote URL from within the green Code dropdown, and then running git clone <project's remote repo url> on your local machine.

Why not to use create React app in production?

However, it is not created for production. Unfortunately, devs have been using it for all their projects. CRA limits your ability to change any configurations, it has tons of unneeded dependencies, you can't customize configurations, you can't build microfrontends …

Is it possible to set up Jit in create-react-app?

I tried setting up the JIT in create-react-app by myself but it doesn't seem to be working as in the styles are not getting updated. I am using craco to build the app with tailwind css and also added TAILWIND mode=WATCH as they suggested to make it work with most builds . Here are my configs:

When should I JIT activate a component?

Privacy policy. Submit Thank you. In this article You should configure a component to be JIT activated only when it is correctly written to support the COM+ Just-in-Time (JIT) Activation service. If a component is deactivated between method calls, it will lose any associated state.

What is just in time (JIT) access control?

When just-in-time access is enabled, privileges are elevated temporarily only for the duration specified, after which they are automatically revoked. Why Just In Time (JIT) Access control is important?

How to enable JIT activation for a component in Revit?

In the component properties dialog box, click the Activationtab. To enable JIT activation for the component, select the Enable Just In Time Activationcheck box. Click OK. When you have enabled JIT Activation for a component, you have the option of enabling the auto-done feature for any method exposed by that component.


3 Answers

If you are on Windows (as I suspect you might be from your comment on @Ako's answer), then your setup is correct but you just need to install cross-env, then adjust your start script like so:

"start": "cross-env TAILWIND_MODE=watch craco start"
like image 63
planetClaire Avatar answered Oct 01 '22 18:10

planetClaire


you must use TAILWIND_MODE=watch in your start script not build, and after you have developed what you want build it just with craco build script. so your package.json scripts must look like this:

  "scripts": {
    "start": "TAILWIND_MODE=watch craco start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject",
  },

also in purge prop inside the tailwind.config.css file you must add './src/components/*.{js,jsx}' so purge should look like this:

purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html', './src/components/*.{js,jsx}'],

and after you built your app you must serve the index.html file inside build folder.

clone this repo and after building the project use npm run servebuild and see if it works. https://github.com/ako-v/cra-tailwindcss-jit-craco

like image 25
Ako Avatar answered Oct 01 '22 17:10

Ako



So you have to watch your JSX, JS, HTML files using the ```--watch``` option provided in tailwindcss CLI,
So what you can do is open up a new terminal in the root of the react project and follow the command below
npx tailwindcss -o ./src/App.css --watch
  • [-i] you can provide a input file also using this option.
  • [-o] modify the output as per your folder structure.

This will make sure to rebuild the CSS file, Next step is to open up another terminal and do npm start and your development server is ready with JIT compiler.

(side note)
Also, I use tailwind with my default configuration of the package.json and it also works smoothly without craco (both JIT / default) and in production.

like image 32
SARAN SURYA Avatar answered Oct 01 '22 16:10

SARAN SURYA