


What this article brings to you is a summary of methods for optimizing directory structure in front-end projects. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Directory structure optimization
Now front-end projects are becoming more and more like large-scale projects, and they are becoming more and more complex. Collaboration between team members needs to be handled well, and business needs to be done well. Blocking and decoupling reduce maintenance costs while maintaining high-efficiency development.
Optimizing the project directory structure is one way to achieve this goal. Generally speaking, whether it is a multi-page project or a single-page application, or both, the directory structure is the following two ways:
type grouping (by file type, business type, etc. Grouping)
Module block (block by page module, business module, etc.)
1. Type grouping
This method is to group by file type, business type or other types.
Multi-page project
|-- src/ 源代码目录 |-- html/ html 文件目录 |-- page1.html page1 页面的 html 文件 |-- module1/ 子目录 |-- page2.html page2 页面的 html 文件 |-- ... |-- ... |-- js/ js 文件目录 |-- common/ 公共文件目录 |-- page1/ page1 页面的 js 目录 |-- module1/ 子目录 |-- page2/ page2 页面的 js 目录 |-- ... |-- ... |-- css/ css 文件目录 |-- common/ 公共文件目录 |-- page1/ page1 页面的 css 目录 |-- module1/ 子目录 |-- page2/ page2 页面的 css 目录 |-- ... |-- ... |-- less/ less 文件目录(内部结构跟上面类似) |-- images/ 图片文件目录(内部结构跟上面类似) |-- data/ api-mock 文件目录(内部结构跟上面类似) |-- ...
Single-page application
|-- src/ 源代码目录 |-- components/ 组件文件目录(如 react) |-- common/ 公共文件目录 |-- page1.js page1 页面的组件文件 |-- module1/ 子目录 |-- page2.js page2 页面的组件文件 |-- ... |-- ... |-- services/ service 文件目录 |-- service1.js page1 页面的 service |-- module1/ 子目录 |-- service2.js page2 页面的 service |-- ... |-- ... |-- models/ model 文件目录 |-- model1.js page1 页面的 model |-- module1/ 子目录 |-- model2.js page2 页面的 model |-- ... |-- ... |-- ... |-- images/ 图片文件目录(内部结构跟上面类似) |-- data/ api-mock 文件目录(内部结构跟上面类似) |-- ...
The advantage of this method is that it can make the file classification and function classification very clear, and it can constrain the writing method (directory structure) of team members to a certain extent. It is also clear, simple and easy to understand. But this method has obvious shortcomings:
It is not easy and quick to know which files a certain page or function block has;
Creating, updating, and deleting pages will become very inefficient because you need to go to different file category directories to find files;
The development efficiency is not high, and it is easy to get tired because the editor When working on a page, you need to expand each file in the editor's file navigation, and the navigation will be very long.
So, for front-end projects, in most cases I will not use this directory structure.
2. Module Blocking
This method is divided into page modules, business modules or other types.
Multi-page project
|-- src/ 源代码目录 |-- page1/ page1 页面的工作空间 |-- index.html html 入口文件 |-- index.js js 入口文件 |-- index.(css|less|scss) 样式入口文件 |-- html/ html 片段目录 |-- js/ js 文件目录 |-- (css|less|scss)/ 样式文件目录 |-- data/ 本地 json 数据模拟 |-- images/ 图片文件目录 |-- components/ 组件目录(如果基于 react, vue 等组件化框架) |-- ... |-- module1/ 子目录 |-- page2/ page2 页面的工作空间(内部结构跟 page1 类似) |-- ... |-- html/ 公共 html 片段 |-- less/ 公共 less 目录 |-- components/ 公共组件目录 |-- images/ 公共图片目录 |-- data/ 公共 api-mock 文件目录 |-- ...
Single-page application
|-- src/ 源代码目录 |-- page1/ page1 页面的工作空间 |-- index.js 入口文件 |-- service.js |-- model.js |-- data/ 本地 json 数据模拟 |-- images/ 图片文件目录 |-- components/ 组件目录(如果基于 react, vue 等组件化框架) |-- ... |-- module1/ 子目录 |-- page2/ page2 页面的工作空间(内部结构跟 page1 类似) |-- ... |-- images/ 公共图片目录 |-- data/ 公共 api-mock 文件目录 |-- components/ 公共组件目录 |-- ...
This method avoids the problem of "type grouping", but it also has some shortcomings:
The constraints on group members are very small, and the directory structure under each workspace can be completely different;
The directory structure under the workspace is not easy to define, and the requirements for developers are higher.
Although there are some shortcomings, they can be eliminated with the build tool, so generally I will choose this directory structure.
3. Use together
In many cases, these two methods can be used together, such as a small single-page application in a multi-page project.
|-- src/ 源代码目录 |-- page1/ page1 页面的工作空间 |-- index.html html 入口文件 |-- index.js js 入口文件 |-- index.(css|less|scss) 样式入口文件 |-- html/ html 片段目录 |-- js/ js 文件目录 |-- ajax/ 对 ajax 封装的目录 |-- util/ 工具类函数的目录 |-- pages/ spa 应用页面目录 |-- data/ 静态数据目录 |-- tpl/ 模板目录 |-- (event|view)/ 事件监听文件目录 |-- ... |-- data/ 本地 json 数据模拟 |-- (css|less|scss)/ 样式文件目录 |-- images/ 图片文件目录 |-- components/ 组件目录(如果基于 react, vue 等组件化框架) |-- ... |-- ...
The above is the detailed content of Summary of methods for optimizing directory structure in front-end projects. For more information, please follow other related articles on the PHP Chinese website!

vscode自身是支持vue文件组件跳转到定义的,但是支持的力度是非常弱的。我们在vue-cli的配置的下,可以写很多灵活的用法,这样可以提升我们的生产效率。但是正是这些灵活的写法,导致了vscode自身提供的功能无法支持跳转到文件定义。为了兼容这些灵活的写法,提高工作效率,所以写了一个vscode支持vue文件跳转到定义的插件。

JavaScript 不提供任何内存管理操作。相反,内存由 JavaScript VM 通过内存回收过程管理,该过程称为垃圾收集。

Node 19已正式发布,下面本篇文章就来带大家详解了解一下Node.js 19的 6 大特性,希望对大家有所帮助!

选择一个Node的Docker镜像看起来像是一件小事,但是镜像的大小和潜在漏洞可能会对你的CI/CD流程和安全造成重大的影响。那我们如何选择一个最好Node.js Docker镜像呢?

本篇文章给大家整理和分享几个前端文件处理相关的实用工具库,共分成6大类一一介绍给大家,希望对大家有所帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
