Playing Next Lesson In
seconds

Transcript

  1. So let's go ahead and create that now. So let's do npm init adonis-ts-app@latest. And let's call this edgejs-components.

  2. Select the web project structure. Project name's fine. We can go ahead and select eslint. We can do prettier. And let's go ahead and configure Webpack Encore so that we get those frontend assets compiled.

  3. Okay, awesome. Let's go ahead and cd into edgejs-components. Clear that out. So we're now ready to go ahead and install the packages that we're going to need for our UI components.

  4. Now, Pine's UI doesn't need anything itself installed. It just builds off of Tailwind CSS and AlpineJS. So what we're going to need to do is install those two libraries.

  5. Let's go ahead and start with Tailwind CSS. I already have it open here in the background. We have a guide on how to do this on Adocasts if you want to follow that. There's also a guide directly within the documentation.

  6. You go get started there. Work guide, scroll down a little bit. There is AdonisJS right there. Go ahead and click on that. It's going to start you at creating your project. We already did that.

  7. We can skip straight to step number two. Go ahead and copy that. Jump into our terminal, paste that in.

  8. It's going to get Tailwind CSS installed as well as PostCSS, PostCSS Loader, Auto Prefixer.

  9. And then it kind of blends in a little bit down here, but this did also run npx tailwindcss-p, which created our Tailwind CSS configuration as well as our PostCSS configuration file.

  10. Our next step is going to require opening up our projects. Let's go ahead and do that. Okay, I've got my project open here.

  11. Let's go ahead and dive down into our webpack-config.js and let's run a search for PostCSS. And you should see Encore Enable PostCSS Loader. Go ahead and just uncomment that.

  12. So next, Tailwind CSS does come with Purge CSS. Purge CSS is going to get rid of all of the unused styles from our style sheet whenever we actually build out our final dist files.

  13. So we'll want to go ahead and inform it what files to look at to determine whether or not we're using a class. And for that, that will be inside of our TailwindConfig.js.

  14. We can go ahead and copy this command right here at step number four. Dive down to our TailwindConfig.js and that copy command probably gave us everything. So we should be able to just overwrite what we have currently.

  15. And this content array is basically telling Purge CSS to look within our resources directory,

  16. any folder within there, and any file ending with the extension edge.js, ts, jsx, tsx, and view.

  17. The next step that we need to do is paste those Tailwind CSS directives within our CSS file. So we can dive back into the documentation, give this a quick copy, dive back into our

  18. project, go within resources, CSS, app CSS. And we can go ahead and get rid of everything and just paste in what we've copied from the documentation. And now we should be good to go with Tailwind CSS.

  19. We'll give that a test here in a second, but first let's go ahead and get Alpine.js installed and configured. So Alpine.js is a little bit more straightforward.

  20. We just need to dive back into our terminal here, npm i alpine.js. All right, that installed just fine.

  21. Now we can go ahead and dive into our js file, app.js, leave that import in there, and then go ahead and do import Alpine from Alpine.js.

  22. And then we just need to initialize it by running alpine.start. Give that a save. We should be good to go there. Let's dive into our views file, go into welcome.

  23. Let's go ahead and just replace everything inside of our main with a simple h1. We'll give this a class of text red 500.

  24. And then to test out Alpine, let's do x data equals text of hello, and we can do x text of text. Go ahead and give that a save.

  25. Jump back into our terminal, npm run dev. Should start up our server. Let's go ahead and open that up. And there we go. So we have red text of hello.

  26. So everything appears to be working just fine.

Getting Started, Installing AlpineJS and TailwindCSS

In This Lesson

We'll quickly create a new AdonisJS 5 project to house our components. Then, we'll install the dependencies needed by PinesUI; AlpineJS and TailwindCSS.

Created by
@tomgobich
Published

Before we start learning EdgeJS’ component system and building our components, we’re first going to need a project to work within. We’ll also need to get AlpineJS and TailwindCSS installed and configured.

Create a New Project

First, we’ll need to set up a new project to work with. To do this, we’ll run the following command, replacing edgejs-components with your preferred project name:

npm init adonis-ts-app@latest edgejs-components
Copied!

When prompted, select the web project structure, and leave the project name as it is. You can also choose to include ESLint and Prettier at this stage. Additionally, configure Webpack Encore to compile frontend assets.

Once the project is created, let's navigate to our project by running:

cd edgejs-components
Copied!

Install Required Libraries

Next, let's install the necessary libraries for our UI components. PinesUI builds on TailwindCSS and AlpineJS but doesn’t require any packages of its own, so we’ll just need to install these two.

Install TailwindCSS

Let's start by installing TailwindCSS by running the following commands:

npm install -D tailwindcss postcss postcss-loader autoprefixer
npx tailwindcss init -p
Copied!

This command installs TailwindCSS, PostCSS, PostCSS Loader, and AutoPrefixer. It also creates configuration files for TailwindCSS and PostCSS.

Configure TailwindCSS

Next, we’ll need to enable the PostCSS Loader in our Webpack configuration. Open your project in your code editor and navigate to webpack.config.js. Search for "PostCss," and uncomment the line that reads Encore.enablePostCssLoader().

Configure PurgeCSS

PurgeCSS is included with TailwindCSS and helps remove unused styles. To configure it, we’ll need to modify our tailwind.config.js file. At this point, you can replace everything in this file with the below.

// tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./resources/**/*.{edge,js,ts,jsx,tsx,vue}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
Copied!

This content array tells PurgeCSS to look within the resources directory for files with specific extensions (e.g., .edge, .js, .ts, .jsx, .tsx, .vue).

Adding TailwindCSS Directives

Now let's replace the content of our CSS file with the directives from TailwindCSS. Navigate to resources/css/app.css and replace its contents with the directives below.

// resources/css/app.css

@tailwind base;
@tailwind components;
@tailwind utilities;
Copied!

Test Tailwind CSS

Now, we can test if TailwindCSS is working as expected by adding some classes to our HTML in our project's welcome view file.

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  @entryPointStyles('app')
</head>
<body>
  <h1 class="text-3xl font-bold underline text-red-500">
    Hello world!
  </h1>
</body>
</html>
Copied!
  • resources
  • views
  • welcome.edge

Install AlpineJS

Lastly, to install AlpineJS, run the following command:

npm i alpinejs
Copied!

Configure AlpineJS

Then, let's open our JavaScript file (app.js) and import AlpineJS then initialize it.

import Alpine from 'alpinejs';
Alpine.start();
Copied!
  • resources
  • js
  • app.js

Test Your Setup

Finally, to verify that everything is set up correctly, let's open back up our welcome.edge view file and apply some AlpineJS to it.

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  @entryPointStyles('app')
</head>
<body>
  <h1 
    x-data="{ text: 'Hello world!' }" 
    x-text="text"
    class="text-3xl font-bold underline text-red-500">
  </h1>
</body>
</html>
Copied!
  • resources
  • views
  • welcome.edge

Save the changes, run npm run dev in your terminal to boot the server up, and check your welcome page to see if your h1 is red and says “Hello world!”.

Join the Discussion 0 comments

Create a free account to join in on the discussion
robot comment bubble

Be the first to comment!