Recap
The last section went through the process of setting up the server side of Stackpress as well as demonstrating the server side interaction with the client side. Before we begin, make sure your code generally syncs up with the project explorer below.
PROJECT
config
develop.ts
plugins
app
pages
home.ts
views
home.tsx
plugin.ts
package.json
tsconfig.json
develop.ts
home.ts
home.tsx
plugin.ts
package.json
tsconfig.json
❐ Copy
❐ Copy
❐ Copy
❐ Copy
❐ Copy
❐ Copy
If you are all caught up, then you can proceed to the next section.
5. View Engine
The view engine of Stackpress uses a sub-project called Reactus which is built on top of Vite. The project allows to use React as a template engine.
5.1. Install UnoCSS
First thing to do is to install the UnoCSS package. Open up the package.json file and add the following package.
❐ Copy
UnoCSS is a utility-first CSS engine that allows you to use atomic classes in your project. It is a very powerful tool that allows you to write CSS in a very efficient way and better APIs to create custom classes.
5.2. Configure UnoCSS
Next, let's create a unocss.config.ts file in the root of the project with the following code. This file will contain the configuration for the UnoCSS engine.
❐ Copy
adds the Tailwind CSS v3 class name rules to the project and adds pixel, hex, rgb, theme, and desktop first rules to the project.
5.3. Configure View Engine
Next, let's configure the view engine to use the UnoCSS by adding the following code to theconfig/develop.ts file.
❐ Copy
is an array of css files that will be computed by every view in the project. This is different from styles found in the public folder, which are static files you can add in the component per view. These static files are loaded before the client app script, and are loaded with the client app script.
is an array of plugins that will be used by the view engine. This is where you can theoretically add any vite plugins you want to use in your project.
5.4. Update View
Before we run the server, let's update the plugins/app/views/home.tsxfile to use the UnoCSS classes. The following code will add the UnoCSS classes to the component.
❐ Copy
The class will add padding all around the component, the class will increase the font size, and the class will bold the text. weight to the component. All of these afformentioned classes are Tailwind CSS classes.
5.5. Run the Server
- 1. In Terminal, run
- 2. On your browser, visit http://localhost:3000/
5.6. Check Point
So far this project demonstrates how a pluggable project structure that can be used to build a web application with the following objectives achieved.
- • The project to uses the EcmaScript Module standard.
- • The project demonstrates a plugin architecture with defined folders for use as a plugin.
- • The example plugin app containing an example page controller and view.
- • The example plugin app demonstrating how a view is rendered from a server side router.
- • The example plugin app demonstrating how props are passed to the view.
- • The project is configured to use a style engine.
If your final files and project code look like the following, then...
PROJECT
config
develop.ts
plugins
app
pages
home.ts
views
home.tsx
plugin.ts
package.json
tsconfig.json
unocss.config.ts
develop.ts
home.ts
home.tsx
plugin.ts
package.json
tsconfig.json
unocss.config.ts
❐ Copy
❐ Copy
❐ Copy
❐ Copy
❐ Copy
❐ Copy
❐ Copy
CONGRATS: You have completed this tutorial.
Relax and take a break and when ready, the next tutorial will cover setting up the Stackpress toolkit with many goodies like database, authentication, sessions, roles & permissions, i18n, API, and more.