Oblique 开源项目教程
1. 项目的目录结构及介绍
Oblique 项目的目录结构如下:
Oblique/
├── README.md
├── package.json
├── public/
│ ├── index.html
│ └── manifest.json
├── src/
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ └── serviceWorker.js
└── yarn.lock
目录结构介绍
- README.md: 项目的基本介绍和使用说明。
- package.json: 项目的依赖管理文件,包含项目的名称、版本、依赖包等信息。
- public/: 公共资源目录,包含
index.html
和manifest.json
。- index.html: 项目的入口 HTML 文件。
- manifest.json: 应用的配置文件,用于 PWA (渐进式 Web 应用)。
- src/: 源代码目录,包含应用的主要代码。
- App.css: 应用的主要样式文件。
- App.js: 应用的主要逻辑文件。
- App.test.js: 应用的测试文件。
- index.css: 全局样式文件。
- index.js: 应用的入口文件。
- logo.svg: 应用的 Logo 文件。
- serviceWorker.js: 服务工作线程文件,用于 PWA。
- yarn.lock: 依赖包的锁定文件,确保依赖包版本一致。
2. 项目的启动文件介绍
项目的启动文件是 src/index.js
,它是整个应用的入口点。以下是 index.js
的主要内容:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
启动文件介绍
- 导入依赖: 导入了 React、ReactDOM 和其他必要的模块。
- 渲染应用: 使用
ReactDOM.render
方法将App
组件渲染到index.html
中的root
元素。 - 服务工作线程: 配置服务工作线程,用于 PWA。
3. 项目的配置文件介绍
项目的配置文件主要是 package.json
和 public/manifest.json
。
package.json
package.json
文件包含了项目的元数据和依赖信息。以下是部分内容:
{
"name": "oblique",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",