现代前端开发工作流
建立高效的前端开发工作流是提高团队生产力的关键。
## 代码规范
### ESLint 配置
``javascript
// eslint.config.js
module.exports = {
extends: ['next/core-web-vitals'],
rules: {
'prefer-const': 'error',
'no-unused-vars': 'warn'
}
};
`
### Prettier 配置
json
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80
}
`
## 版本控制
### Git Hooks
`json
{
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
`
## 测试策略
### 单元测试
`tsx
import { render, screen } from '@testing-library/react';
import Button from './Button';
test('renders button with text', () => {
render();
expect(screen.getByText('Click me')).toBeInTheDocument();
});
`
## 部署流程
### CI/CD 配置
`yaml
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm ci
- run: npm run build
- run: npm run deploy
``
## 总结
良好的开发工作流是项目成功的基础,值得投入时间进行优化和完善。
// eslint.config.js
module.exports = {
extends: ['next/core-web-vitals'],
rules: {
'prefer-const': 'error',
'no-unused-vars': 'warn'
}
};
### Prettier 配置
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80
}
## 版本控制
### Git Hooks
{
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
## 测试策略
### 单元测试
import { render, screen } from '@testing-library/react';
import Button from './Button';
test('renders button with text', () => {
render();
expect(screen.getByText('Click me')).toBeInTheDocument();
});
## 部署流程
### CI/CD 配置
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm ci
- run: npm run build
- run: npm run deploy