1 | # 使用
|
2 |
|
3 | 安装
|
4 |
|
5 | ```shell script
|
6 | yarn add @gm-react-app/scripts
|
7 | ```
|
8 |
|
9 | 迁移指引
|
10 |
|
11 | ```shell script
|
12 | gras migrate
|
13 | ```
|
14 |
|
15 | 之后跟着指引做就对了
|
16 |
|
17 | # 说明
|
18 |
|
19 | ## 文件夹
|
20 |
|
21 | ```
|
22 | my-project
|
23 | build/
|
24 | config/
|
25 | deploy.js
|
26 | local.js
|
27 | webpack.config.js
|
28 | src/
|
29 | index.js
|
30 | index.html
|
31 | svg/
|
32 | xxx.svg
|
33 | .eslintrc.js
|
34 | .gitignore
|
35 | .prettierrc.js
|
36 | .stylelintrc
|
37 | babel.config.js
|
38 | package.json
|
39 | yarn.lock
|
40 | ```
|
41 |
|
42 | /build 构建产物
|
43 |
|
44 | 配置 /config/deploy.js /config/local.js
|
45 |
|
46 | ```javascript
|
47 | module.exports = {
|
48 | // 生产必填,开发默认 '/build/'
|
49 | publicPath: '//js.guanmai.cn/build/xxxx/',
|
50 | // 默认 8080
|
51 | port: 8080,
|
52 | // 默认不启用
|
53 | https: false,
|
54 | // 代理
|
55 | proxy: [
|
56 | {
|
57 | context: ['/xxxx', '/xxx'],
|
58 | target: 'url',
|
59 | changeOrigin: true,
|
60 | },
|
61 | ],
|
62 | }
|
63 | ```
|
64 |
|
65 | /config/webpack.config.js 如果修改 webpack 配置,提供此文件
|
66 |
|
67 | 入口 /src/index.js
|
68 |
|
69 | 模板 /src/index.html,支持 ejs 语法
|
70 |
|
71 | svg [svgr](https://github.com/gregberge/svgr) 只局限在 /svg 下,避免和其他 svg 冲突
|
72 |
|
73 | ## babel
|
74 |
|
75 | 默认值解析 src/目录下和 node_modules/下的 gm-、@gmfe、@gm-touch,其他请联系作者 or 自行补充
|
76 |
|
77 | ## css
|
78 |
|
79 | less
|
80 |
|
81 | style-jsx
|
82 |
|
83 | ## 其他
|
84 |
|
85 | react-hot-loader
|
86 |
|
87 | 默认做了 alias
|
88 |
|
89 | ```
|
90 | alias: {
|
91 | // yarn link 后保持 react 一致
|
92 | react: path.resolve('react'),
|
93 | common: PATH.appDirectory + 'src/js/common/',
|
94 | stores: PATH.appDirectory + 'src/js/stores/',
|
95 | svg: PATH.appDirectory + 'src/svg/',
|
96 | img: PATH.appDirectory + 'src/img/'
|
97 | }
|
98 | ```
|
99 |
|
100 | 环境
|
101 |
|
102 | ```
|
103 | process.env.NODE_ENV development test production
|
104 | process.env.GIT_BRANCH
|
105 | process.env.GIT_COMMIT
|
106 | ```
|
107 |
|
108 | 变量
|
109 |
|
110 | ```
|
111 | __DEBUG__
|
112 | __DEVELOPMENT__
|
113 | __TEST__
|
114 | __PRODUCTION__
|
115 | __VERSION__ 来自 package.json version
|
116 | __NAME__ 来自 package.json aliasName
|
117 | __CLIENT_NAME__ 来自 package.json clientName
|
118 | __BRANCH__
|
119 | __COMMIT__
|
120 | ```
|
121 |
|
122 | 模板变量
|
123 |
|
124 | ```
|
125 | htmlWebpackPlugin.options.branch
|
126 | htmlWebpackPlugin.options.commit
|
127 | htmlWebpackPlugin.options.env
|
128 | ```
|