Set Up a Front-End Project

A beginner's guide to setting up a front-end project from scratch, including project structure and development tools

🎯 Introduction

In this article, you will learn how traditional front-end projects differ from projects that use modern engineering practices, explore common development tools, and set up a modern front-end project step by step to improve efficiency and code quality.


🏚 What Does a Traditional Project Look Like?

Many beginners start building websites with a structure like this:

home.html
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>My First Web Page</title>
    </head>
    <body>
        <h1>Welcome to My Web Page</h1>
        <p>This is the main content.</p>
    </body>
</html>

All the code lives in a few large files, with page structure, styles, and logic mixed together. CSS and JavaScript might be embedded in index.html or split into a few separate files. This can work for a small project, but maintenance and collaboration become harder as the code grows:

  • Files become disorganized and lack a clear structure
  • Code is difficult to reuse, and features are tightly coupled
  • There is no build process, making it cumbersome to deploy changes

🏗 What Does a Structured Front-End Project Look Like?

A project built around engineering practices has a clear structure and separates responsibilities. A typical project might look like this:

package.json
{
    "name": "my-project",
    "dependencies": {
        "vue": "^3.3.10"
    }
}
my-project/
  ├─ dist/            # Build output containing production code
  ├─ node_modules/    # Project dependencies
  ├─ public/          # Static assets such as images and favicons
  ├─ src/             # Source code: core pages, components, styles, and scripts
  │    ├─ components/ # Reusable UI components
  │    ├─ styles/     # CSS and preprocessor files
  │    ├─ utils/      # Utility functions
  │    ├─ App.vue     # Root component
  │    └─ main.js    # Main entry point that mounts the app
  ├─ package.json     # Project configuration and dependency management
  ├─ webpack.config.js# Build tool configuration (when using webpack)
  └─ .eslintrc.js     # Linting configuration

This structure separates code into clear, logical parts, making collaboration and maintenance easier. Each part has a single responsibility: components handle the UI, for example, while utility functions provide shared logic.


⚙️ Which Tools Do You Need?

Common tools and technologies for a structured front-end project include:

  • Package managers: Manage project dependencies. Common choices include npm and Yarn.
  • Module bundlers and build tools: Turn code from multiple modules into files browsers can load. Common choices include webpack, Vite, and Rollup.
  • Linting and formatting tools: Keep code consistent. Common choices include ESLint and Prettier.
  • UI libraries and frameworks: Help build user interfaces. Common choices include React, Vue, and Angular.
  • Preprocessors: Provide more flexible ways to write CSS, such as Sass and Less.
  • Automation scripts: Use npm scripts or other tools to automate bundling, testing, and deployment.
  • Version control tools: Tools such as Git support collaboration and code management.

Together, these tools make development efficient and consistent.


🚀 How Do You Set Up a Project from Scratch?

1. Install Node.js

Node.js is essential for this development workflow. Visit the official Node.js website and download and install a long-term support (LTS) version. Then open a terminal and check the installation:

node -v
npm -v

If both commands display version numbers, the installation was successful.

2. Create a Project Directory

Create a project folder wherever you prefer. For example:

mkdir my-project
cd my-project

3. Initialize the Project Configuration

npm init

The terminal will prompt you for details such as the project name, version, and description. Press Enter to accept the default values.

Once the command finishes, you will see a new package.json file in the project directory. This file records the development packages installed in your project and their versions, making it a key part of the setup.

4. Project Initialization Complete

You now have the most basic foundation for a structured front-end project. Its directory looks like this:

my-project/
├── package.json

5. What Comes Next?

You can now install development tools as needed. The next article explains how to install and use webpack in your project.


🧾 Section Summary

  • Traditional projects have a simple structure but can become disorganized and difficult to maintain.
  • Projects built around engineering practices have a clear hierarchy and well-defined responsibilities.
  • Common tools include package managers, bundlers, linting and formatting tools, and UI frameworks.
  • You can quickly set up a structured front-end project with Vite in a few simple steps.

❓ Knowledge Check

Q1: Why use a module bundler? When module code cannot run directly in a browser, a bundler combines the separate modules into files the browser can execute.

Q2: What is the purpose of package.json? It is the project's configuration file, used to manage dependencies and automation scripts.


🧪 Practice Exercise

  1. Set up a Node.js environment by downloading and installing Node.js from its official website.
  2. Follow the steps above to create your own structured front-end project with a package.json file.

🎉 You now know the basics of setting up a front-end project with engineering practices! Put them into practice and build an efficient project of your own.