Skip to content

Commit 0f73eb1

Browse files
author
kaiyu.kong
committed
feat: webpack
1 parent 0c94cd1 commit 0f73eb1

34 files changed

+1102
-0
lines changed

packages/webpack-template/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# README
2+
3+
webpack-template
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@enode/webpack-template",
3+
"version": "1.0.0",
4+
"keywords": [],
5+
"description": "",
6+
"author": "kaiyu.kong",
7+
"maintainers": [
8+
"kaiyu.kong"
9+
],
10+
"main": "template.json",
11+
"license": "MIT",
12+
"files": [
13+
"template",
14+
"template.json"
15+
],
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"gitHead": "9a14bb5597f99422559907fa9ae33e3a75bf4818"
20+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"package": {
3+
"description": "",
4+
"keywords": [],
5+
"license": "MIT",
6+
"private": true,
7+
"author": "",
8+
"dependencies": {
9+
"react": "^19.1.0",
10+
"react-dom": "^19.1.0",
11+
"react-scripts": "5.0.1"
12+
},
13+
"scripts": {
14+
"start": "env-cmd -e development craco start",
15+
"build": "yarn build-prod",
16+
"test": "craco test",
17+
"build:analyze": "cross-env BUILD_ANALYZER=true yarn build-prod",
18+
"build-test": "env-cmd -e test craco build",
19+
"build-prod": "env-cmd -e production craco build",
20+
"commit": "git-cz",
21+
"changelog": "standard-version -n"
22+
},
23+
"eslintConfig": {
24+
"extends": [
25+
"react-app",
26+
"react-app/jest",
27+
"./node_modules/@umijs/fabric/dist/eslint"
28+
],
29+
"rules": {
30+
"@typescript-eslint/consistent-type-definitions": 0,
31+
"@typescript-eslint/no-invalid-this": 0,
32+
"@typescript-eslint/consistent-type-imports": 0,
33+
"@typescript-eslint/no-shadow": 0,
34+
"@typescript-eslint/no-unused-vars": 1,
35+
"no-underscore-dangle": 0,
36+
"import/no-extraneous-dependencies": 0,
37+
"import/no-dynamic-require": 0,
38+
"react/sort-comp": 0,
39+
"jsx-a11y/aria-role": 0,
40+
"jsx-a11y/alt-text": 0,
41+
"jsx-a11y/anchor-has-content": 0,
42+
"jsx-a11y/control-has-associated-label": 0,
43+
"no-param-reassign": 0,
44+
"prefer-object-spread": 0,
45+
"consistent-return": 0,
46+
"react/button-has-type": 0,
47+
"react/react-in-jsx-scope": 0,
48+
"prefer-destructuring": 0,
49+
"array-callback-return": 0,
50+
"no-plusplus": 0,
51+
"no-nested-ternary": 0,
52+
"no-unused-expressions": 0,
53+
"react/no-unknown-property": [
54+
"error",
55+
{
56+
"ignore": [
57+
"styleName"
58+
]
59+
}
60+
]
61+
}
62+
},
63+
"browserslist": {
64+
"production": [
65+
">0.2%",
66+
"not dead",
67+
"not op_mini all"
68+
],
69+
"development": [
70+
"last 1 chrome version",
71+
"last 1 firefox version",
72+
"last 1 safari version"
73+
]
74+
},
75+
"yxpm": {
76+
"output": [
77+
"dist"
78+
]
79+
},
80+
"devDependencies": {
81+
"@babel/plugin-proposal-class-properties": "^7.10.4",
82+
"@babel/plugin-proposal-decorators": "^7.10.5",
83+
"@commitlint/cli": "9.1.2",
84+
"@commitlint/config-conventional": "9.1.2",
85+
"@craco/craco": "^6.0.0",
86+
"@testing-library/jest-dom": "^5.14.1",
87+
"@testing-library/react": "^13.0.0",
88+
"@testing-library/user-event": "^13.2.1",
89+
"@types/css-modules": "^1.0.2",
90+
"@types/jest": "^27.0.1",
91+
"@types/node": "^16.7.13",
92+
"@types/react": "^18.0.0",
93+
"@types/react-css-modules": "^4.6.2",
94+
"@types/react-dom": "^18.0.0",
95+
"@umijs/fabric": "^2.5.13",
96+
"babel-plugin-import": "^1.13.0",
97+
"babel-plugin-module-resolver": "^4.1.0",
98+
"babel-plugin-react-css-modules": "^5.2.6",
99+
"circular-dependency-plugin": "^5.2.0",
100+
"commitizen": "^4.2.1",
101+
"craco-less": "^1.17.0",
102+
"craco-plugin-scoped-css": "^1.1.1",
103+
"craco-scoped-less": "^1.0.3",
104+
"cross-env": "^7.0.2",
105+
"cz-conventional-changelog": "^3.3.0",
106+
"env-cmd": "^10.1.0",
107+
"fs-extra": "^10.0.1",
108+
"generic-names": "^3.0.0",
109+
"http-proxy-middleware": "^1.0.5",
110+
"lint-staged": "^11.0.0",
111+
"postcss-less": "^3.1.4",
112+
"postcss-scss": "^3.0.0",
113+
"prettier": "^2.3.2",
114+
"standard-version": "^9.3.1",
115+
"typescript": "^4.4.2",
116+
"typescript-plugin-css-modules": "^5.0.1",
117+
"vconsole-webpack-plugin": "^1.5.2",
118+
"web-vitals": "^2.1.0",
119+
"webpack-bundle-analyzer": "^3.9.0",
120+
"webpackbar": "^5.0.0-3",
121+
"yorkie": "^2.0.0"
122+
},
123+
"gitHooks": {
124+
"pre-commit": "lint-staged --allow-empty",
125+
"commit-msg": "commitlint -E GIT_PARAMS"
126+
},
127+
"eslintIgnore": [
128+
"src/setupProxy.js"
129+
],
130+
"lint-staged": {
131+
"**/*.{js,jsx,json,css,scss,less,html,md}": [
132+
"prettier --write"
133+
],
134+
"src/**/*.{ts,tsx}": [
135+
"prettier --parser=typescript --write"
136+
],
137+
"src/**/*.{ts,tsx,js,jsx}": [
138+
"eslint --fix --max-warnings 0"
139+
]
140+
},
141+
"prettier": {
142+
"arrowParens": "avoid",
143+
"trailingComma": "es5",
144+
"singleQuote": true,
145+
"semi": true,
146+
"tabWidth": 2
147+
},
148+
"config": {
149+
"commitizen": {
150+
"path": "./node_modules/cz-conventional-changelog"
151+
}
152+
},
153+
"antdTheme": {}
154+
}
155+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* https://commitlint.js.org/#/reference-configuration
3+
*/
4+
module.exports = {
5+
extends: ['@commitlint/config-conventional'],
6+
ignores: [
7+
commit => {
8+
// 不校验 create-react-app 初始化创建时的 commit message
9+
return commit.includes('Initialize project using Create React App');
10+
},
11+
],
12+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* env-cmd 注入 node 运行环境变量
3+
* - env-cmd 支持定义任意多的环境,自动注入定义的环境变量,仅需在 package.json scripts 启动时,通过 -e 指定运行时对应的环境;
4+
* - https://github.com/toddbluhm/env-cmd
5+
*
6+
* Tips:
7+
* 1、自定义的环境变量:
8+
* - 如果你期望在 js 代码中读取,必须以 REACT_APP_ 打头,否则会被 CRA 脚手架经过内部处理忽略掉;
9+
* - 如果仅仅在构建阶段使用,可以不使用 REACT_APP_ 前缀;
10+
* 2、CRA 内置的环境变量列表:https://create-react-app.dev/docs/advanced-configuration
11+
*/
12+
13+
const {
14+
name: projectName,
15+
yxpm: { output: outputDir },
16+
} = require('./package.json');
17+
18+
module.exports = {
19+
development: {
20+
REACT_APP_BUILD_ENV: 'development', // 编译环境
21+
PUBLIC_URL: '', // 配置静态资源 url,最终影响 output下的 publicPath(开发环境不需要配置)
22+
DANGEROUSLY_DISABLE_HOST_CHECK: true, // 允许代理 host 通过 IP 地址访问
23+
// HOST: 'xxx.test.xxxx.com', // 指定启动时的 host(需提前修改 host 映射)
24+
ENABLE_VCONSOLE: false, // 是否开启 vconsole( production 环境即使设置为 true 也不会开启)
25+
},
26+
test: {
27+
REACT_APP_BUILD_ENV: 'test',
28+
PUBLIC_URL: `https://xxx.test.xxxx.com/yx/${projectName}/last/${outputDir}/`,
29+
BUILD_PATH: 'dist', // 自定义打包输出目录
30+
INLINE_RUNTIME_CHUNK: false,
31+
GENERATE_SOURCEMAP: true,
32+
REMOVE_FILENAME_HASH: false, // 是否移除编译产物中 js/css 文件名的 hash 值
33+
ENABLE_VCONSOLE: false,
34+
},
35+
production: {
36+
REACT_APP_BUILD_ENV: 'production',
37+
PUBLIC_URL: `https://xxx.xxx.com/yx/${projectName}/last/${outputDir}/`, // 尽量使用 https,避免运营商劫持资源
38+
BUILD_PATH: 'dist',
39+
INLINE_RUNTIME_CHUNK: false, // runtime 代码是否内嵌到 html 中
40+
GENERATE_SOURCEMAP: true, // 是否开启 sourcemap
41+
REACT_APP_SOURCE_MAPPING_URL: `http://sourcemap.xxxx.com/${projectName}/${outputDir}/`, // 暂时仅支持 http 协议
42+
REMOVE_FILENAME_HASH: false,
43+
SHOULD_DROP_DEBUGGER: true, // 打包时是否移除 debugger
44+
SHOULD_DROP_CONSOLE: true, // 打包时是否移除 console
45+
},
46+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
/dist
14+
15+
# misc
16+
.DS_Store
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
.history
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tsconfig.json
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"typescript.enablePromptUseWorkspaceTsdk": true
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"@xxxx:registry" "http://xnpm.xxxx.com/"
2+
"@x:registry" "http://x.xxxx.com/"

0 commit comments

Comments
 (0)