


Summary of methods for optimizing directory structure in front-end projects
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!

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools
