Friday, April 26, 2024
HomeJavaScriptMeteor.js with Vite, Strong, and Tailwind CSS | by Frederico Maia |...

Meteor.js with Vite, Strong, and Tailwind CSS | by Frederico Maia | Might, 2023


On the planet of internet improvement, selecting the best instruments could make a major distinction within the effectivity and high quality of your initiatives. On this weblog submit, we are going to discover ways to create a brand new challenge utilizing 4 highly effective instruments: Meteor.js, Vite, Strong, and Tailwind CSS. This mix can elevate our improvement expertise.

Meteor.js with Vite, Solid and Tailwind CSS
Meteor.js with Vite, Strong, and Tailwind CSS

Meteor.js is a full-stack platform that simplifies the event of internet functions by offering a unified strategy to constructing each the front-end and back-end. With real-time information updates, Meteor.js hastens the event course of and ensures you’ll be able to create highly effective functions.

Vite is a next-generation construct device that considerably enhances improvement. Integrating Vite with Meteor.js and Strong can additional enhance improvement effectivity and software efficiency.

Strong is a novel JavaScript library designed for creating person interfaces extra effectively. Fairly than utilizing a Digital DOM like many different frameworks, Strong compiles its templates to actual DOM nodes and updates them with exact reactions.

Tailwind CSS is a utility-first CSS framework that permits builders to shortly design responsive, trendy web sites and functions with out writing repetitive CSS code. By offering a set of predefined utility courses, Tailwind CSS streamlines the styling course of, permitting you to give attention to the general format and design.

When mixed, Meteor.js, Vite, Strong, and Tailwind CSS create a strong synergy that may dramatically improve your internet improvement expertise.

Earlier than diving into the tutorial, it is best to know that it is potential to shortly generate a Meteor.js + Vite + Strong app utilizing the next command:

meteor create meteor-solid-app --solid

Nevertheless, on this tutorial, we’ll information you thru every step to supply a deeper understanding of the method.

Begin by creating a brand new Meteor challenge utilizing the --minimal flag. This selection generates a challenge with the minimal required Meteor packages. If you do not have Meteor.js put in but, comply with our directions right here. Upon creation, a subdirectory with the identical title can be created. Please navigate to the challenge folder and run it to make sure the correct setup.

meteor create meteor-solid-app --minimal
cd meteor-solid-app
meteor npm begin

You must see a easy app as beneath:

Minimal Meteor app screenshot
Minimal Meteor app screenshot

To make use of the newest dependencies, evaluate your package deal.json file and replace your dependencies accordingly:

...
"dependencies": {
"@babel/runtime": "^7.21.5",
"meteor-node-stubs": "^1.2.5"
},
...

Run meteor npm i to put in the newly added dependencies above.

Execute the instructions beneath to put in Vite and Strong:

meteor add vite:bundler
meteor npm i -D vite vite-plugin-solid
meteor npm i solid-js

Create a Vite configuration file (vite.config.js) in your challenge root and import the Strong plugin. Since we aren’t utilizing a regular Vite index.html file, specify an entry level to a brand new file that will likely be created contained in the ui folder referred to as important.jsx:

import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid';

export default defineConfig({
plugins: [
solidPlugin(),
],
meteor: {
clientEntry: 'ui/important.jsx',
},
})

Write your code from this entry level, and let Vite deal with it! ⚡️

Create the ui folder and the file ui/important.jsx with the next content material:

import { render } from 'solid-js/internet';
import { Meteor } from "meteor/meteor";
import { App } from "./App";

Meteor.startup(() => {
render(() => <App/>, doc.getElementById('root'));
});

We’ll create the App element later. Now, exchange the contents of shopper/important.html with:

<head>
<title>Meteor.js with Vite, Strong, and Tailwind CSS</title>
</head>
<physique>
<noscript>You want to allow JavaScript to run this app.</noscript>
<div id="root"></div>
</physique>

Delete the content material from shopper/important.js and add a remark as follows:

// The principle entry level for the app may be present in ui/important.jsx.

Set up tailwindcss and its peer dependencies by way of npm, then run the init command to generate each tailwind.config.js and postcss.config.js.

meteor npm i -D tailwindcss postcss autoprefixer
meteor npx tailwindcss init -p

In your tailwind.config.js file, add the paths to your entire template information:

/** @sort {import('tailwindcss').Config} */
module.exports = {
content material: ["./ui/**/*.{js,jsx,ts,tsx}"],
theme: {
lengthen: {},
},
plugins: [],
}

Embrace the Tailwind directives in your shopper/important.css file:

@tailwind base;
@tailwind elements;
@tailwind utilities;

Create the file ui/App.jsx with the next content material:

export const App = () => (
<div className="p-4">
<h1 className="text-3xl font-bold text-indigo-800">
Meteor + Strong + Tailwind
</h1>
</div>
);

From the app folder, run the meteor npm begin command to launch your app. You must see a easy heading with an indigo coloration.

Screenshot of the app with the heading “Meteor + Solid + Tailwind”.
Screenshot of the app with the title “Meteor + Strong + Tailwind”.

Alerts are the muse of reactivity in Strong. They comprise values that change over time; while you replace a sign’s worth, something that makes use of it’s robotically up to date.

To create a sign, import createSignal from solid-js and name it out of your App element. Moreover, create an increment operate that will likely be referred to as when a person clicks a button.

import { createSignal } from "solid-js";

export const App = () => {
const [counter, setCounter] = createSignal(0);
const increment = () => {
setCounter(counter() + 1);
};
...
}

Improve your element to show the counter on the display and embody a button to increment the counter. Your full App element ought to resemble the next:

import { createSignal } from "solid-js";

export const App = () => {
const [counter, setCounter] = createSignal(0);

const increment = () => {
setCounter(counter() + 1);
};

return (
<div className="p-4">
<header>
<h1 className="text-3xl font-bold text-indigo-800">
Meteor + Strong + Tailwind
</h1>
</header>
<part>
<p className="py-4 font-semibold">You've got pressed the button {counter()} instances.</p>
<button
onClick={increment}
sort="button"
className="rounded bg-indigo-800 px-2 py-1 text-sm text-white"
>
Click on Me
</button>
</part>
</div>
);
}

Nice! From the app folder, run meteor npm begin to launch your app.

Animated Gif clicking on the button
Animated Gif clicking on the button

Create a Meteor Cloud account through the use of this URL, log in out of your terminal, and execute the command beneath to deploy it without cost:

meteor login
meteor deploy meteorsolidapp.meteorapp.com --free --mongo

You possibly can additionally create a Git repository along with your challenge and deploy it from there. Learn to do it by studying our information.

By utilizing a meteorapp.com area, there isn’t any must register one only for testing your app. The --free --mongo flags deploy an app utilizing our free plan, together with MongoDB.

Remember the fact that the subdomain meteorsolidapp.meteorapp.com is already in use, so you will want to decide on a distinct one on your app. Now, please share it along with your dev associates!

Get pleasure from exploring the entire supply code for this tutorial on this GitHub repository. If the code has modified because the time of this submit, you’ll be able to all the time discuss with this particular launch for the unique model.

Conclusion

On this weblog submit, we stroll you thru making a Meteor challenge with Strong, Vite, and Tailwind CSS. We cowl establishing the suitable configuration and making your first Strong app.

Tell us if you need to see half 2 of this weblog submit, displaying find out how to join subscriptions and strategies from Meteor to Strong. Bear in mind which you could already see an instance app by producing it from the command line utilizing the --solid flag.

Be at liberty to share your suggestions or ask questions within the feedback beneath. Pleased coding!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments