@@ -94,6 +94,105 @@ npm run build
9494- TypeScript(已经加入)
9595```
9696
97+ ### 顶部加载条
98+ 安装
99+ ```
100+ yarn add nprogress
101+ yarn add @types/nprogress
102+ ```
103+ 使用
104+ ``` js
105+ router .beforeEach (()=> {
106+ NProgress .start ()
107+ })
108+ router .afterEach (() => {
109+ NProgress .done ()
110+ })
111+ ```
112+
113+
114+ ### 抽取公共包,引入CDN
115+ ``` js
116+ const externals = {
117+ vue: ' Vue' ,
118+ ' vue-router' : ' VueRouter' ,
119+ vuex: ' Vuex' ,
120+ axios: ' axios'
121+ }
122+ const cdnMap = {
123+ css: [],
124+ js: [
125+ ' //unpkg.com/vue@2.6.10/dist/vue.min.js' ,
126+ ' //unpkg.com/vue-router@3.0.6/dist/vue-router.min.js' ,
127+ ' //unpkg.com/vuex@3.1.1/dist/vuex.min.js' ,
128+ ' //unpkg.com/axios@0.19.0/dist/axios.min.js'
129+ ]
130+ }
131+ module .exports = {
132+ chainWebpack : config => {
133+ config .externals (externals)
134+ config .plugin (' html' ).tap (args => {
135+ args[0 ].cdn = cdnMap
136+ args[0 ].minify && (args[0 ].minify .minifyCSS = true ) // 压缩html中的css
137+ return args
138+ })
139+ }
140+ }
141+
142+ ```
143+
144+ 然后在index.html里添加
145+ ``` html
146+ <!-- 使用CDN的CSS文件 -->
147+ <% for (var i in
148+ htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.css) { %>
149+ <link href =" <%= htmlWebpackPlugin.options.cdn.css[i] %>" rel =" preload" as =" style" />
150+ <link href =" <%= htmlWebpackPlugin.options.cdn.css[i] %>" rel =" stylesheet" />
151+ <% } %>
152+ <!-- 使用CDN加速的JS文件,配置在vue.config.js下 -->
153+ <% for (var i in
154+ htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %>
155+ <script src =" <%= htmlWebpackPlugin.options.cdn.js[i] %>" ></script >
156+ <% } %>
157+
158+ ```
159+
160+ ### 去除console
161+ 保存测试环境和本地开发环境的console
162+ ```
163+ npm i -D babel-plugin-transform-remove-console
164+ ```
165+ 在 babel.config.js 中配置
166+ ``` js
167+ // 获取 VUE_APP_ENV 非 NODE_ENV,测试环境依然 console
168+ const IS_PROD = [' production' , ' prod' ].includes (process .env .VUE_APP_ENV )
169+
170+ const plugins = [
171+ [
172+ ' import' ,
173+ { libraryName: ' ant-design-vue' , libraryDirectory: ' es' , style: true }
174+ ]
175+ ]
176+
177+ // 去除 console.log
178+ if (IS_PROD ) {
179+ plugins .push (' transform-remove-console' )
180+ }
181+
182+ module .exports = {
183+ presets: [' @vue/cli-plugin-babel/preset' ],
184+ plugins
185+ }
186+
187+
188+ ```
189+
190+ # 关于我
191+ ![ Image text] ( https://github.com/weizhanzhan/antd-vue-admin/blob/typescript_dev/public/me.png )
192+ 加我微信,邀你进入技术交流群,交流学习 😄 共同进步<br >
193+ 如果喜欢请给我一个小♥♥ ⭐ (づ ̄3 ̄)づ
97194
98- <!-- 
99-  -->
195+ # 感谢
196+ [ vue-element-admin] ( https://github.com/PanJiaChen/vue-element-admin ) <br >
197+ [ ant-design-pro-vue] ( https://github.com/sendya/ant-design-pro-vue ) <br >
198+ [ vue-h5-template] ( https://github.com/sunniejs/vue-h5-template )
0 commit comments