webpack5部署vue3商业项目详细流程

web5deployVue3 目录

文章目录

  • 推荐阅读
  • 前言
  • 初始化目录
    • 1. 初始化`webpack.config.js`
    • 2. 安装`webpack`
      • 注意
    • 3. 初始化目录和文件
    • 总结
  • 配置核心功能
    • 问题
    • 1. 安装依赖
    • 2. 修改`webpack.config.js`配置
    • 注意
    • 处理样式
      • 1. 安装依赖
      • 2. 修改`webpack.config.js`配置
      • 注意
    • 处理图片等静态资源
      • 1. 安装依赖
      • 2. 修改`webapck.config.js`配置
    • 创建html文件
      • 1. 安装依赖
      • 2.修改`webpack`配置
      • 注意
    • 开发服务器
      • 1. 安装依赖
      • 2.修改`webpack`配置
    • 清除打包文件
      • 1. 安装依赖
      • 2.修改`webpack`配置
      • 注意
    • 设置环境变量
      • 设置环境变量常见方式
      • 设置
    • 分环境打包
      • 打包压缩
        • 1. 压缩`html`文件
        • 2. 压缩`css`文件
          • 注意
        • 3. 压缩`js`文件
          • 注意
        • 4. 压缩图片
          • 注意
  • 集成TypeScript
    • 配置环境
      • 1. 安装依赖
      • 2. 修改`webpack`配置
      • 3. 初始化`tsconfig.json`文件
      • 注意
    • 重点内容
  • 识别`.Vue`文件
    • 1. 安装依赖
      • 注意
    • 2. 修改`webpack`文件
    • 3. `index.js`文件中引入`vue`
      • 注意
    • Composition API
      • vue2缺失
      • 常用的`Composition API`
      • 深入推荐阅读
      • 响应式系统
        • `vue2.x`核心原理
        • `vue2.x`总结
        • `Vue3`核心原理
      • `vue3`总结
  • 集成 `Vue-Router`
    • 基本使用
      • 1. 安装依赖
      • 2. 创建`Home.vue`和`Me.vue`
      • 3. 创建`router.js`文件
      • 4. 修改`index.js`文件
  • 集成Vuex
    • 基本使用
      • 1. 安装依赖
      • 2. 创建`store.js`文件
      • 3. 修改`index.js`文件
      • 4. 在`App.vue`中获取`vuex`中的数据
        • 注意
  • 集成Vant
    • 1.安装依赖
    • 2.按需引入
      • 1. 依赖
      • 2.修改配置
  • Rem布局适配
    • 1. 安装依赖
    • 2. 添加`.postcssrc.js`
      • 注意
    • 3. 引入和使用
  • 优化
    • 1. 规划目录结构
      • 注意
    • 2. 打包友好提示
      • 1. 安装依赖
      • 2.修改`webpack`配置
    • 3. 分析打包文件大小
      • 1. 依赖
      • 2. 修改`webpack`配置
      • 3. 修改`package.json`
        • 技巧
    • 4. 打包速度
      • 1.安装依赖
        • 注意
      • 2. 修改`webpack`配置
    • 5.缩小打包范围
    • 6. 缓存
      • 1. 安装依赖
      • 2. 修改`webpack`配置
      • 其他
  • 统一代码规范
    • Eslint
    • Perttier
    • stylelint
    • EditorConfig
  • 配置Git Message
    • 1. 依赖
    • 2. 创建`commit.config.js`
    • 3. `package.json`文件中引入`husky`
    • 4. 使用


推荐阅读

  • txm-原文

前言

  • 造轮子理解原理
  • 理解原理后,脚手架提高效率
  • 利用webpack5搭建一个完整的vue3的开发环境

初始化目录


1. 初始化webpack.config.js

npm init -y
效果:
webpack5部署vue3商业项目详细流程_第1张图片

2. 安装webpack

npm install webpack webpack-cli -D

注意

  1. -D等价于--save-dev,开发环境时所需依赖
  2. -S等价于--save,生产环境时所需依赖
    webpack5部署vue3商业项目详细流程_第2张图片
  • 注意更改源

3. 初始化目录和文件

  • 创建webpack.config.js文件用于编写webpack
// webpack.config.js
const path = require('path');

module.exports = {
	mode: 'development',
	entry: './src/index.js',
	output: {
		filename: '[name].js',
		path: path.resolve(__dirname, 'dist')
	}
}
  • 创建src目录存放源代码
// src/index.js
console.log('test webpack');
  • 修改package.json中的scripts字段
  "scripts": {
    "build": "webpack"
  },
  • 打包js
    1. 项目根目录输入npm run build或者只输入webpack
    2. 打包成功后,会在项目的根目录创建一个dist文件夹,打包后的文件就是main.js

效果

webpack5部署vue3商业项目详细流程_第3张图片
在这里插入图片描述

总结

  1. npm初始化
  2. webpack
  3. 修改package.jsonwebpack.config.js
  4. npm run build or webpack

配置核心功能


问题

由于存在一些浏览器无法使用ES6+的高级语法,因此需要转换为ES5

1. 安装依赖

cnpm install @babel/core babel-loader @babel/preset-env -D

2. 修改webpack.config.js配置

// webpack.config.js
const path = require('path');

module.exports = {
	mode: 'development',
	entry: './src/index.js',
	output: {
		filename: '[name].js',
		path: path.resolve(__dirname, 'dist')
	},
	module: {
		rules: [
			{
				test: /\.js$/,
				use: {
					loader: 'babel-loader',
					options: {
						presets: ['@babel/preset-env']
					}
				}
			}
		]
	}
	
}

注意

如果不想将配置写在配置文件中,可以在根目录创建babel.config.js或者babelrc.js


处理样式

  • webpack默认只能打包commonJS规范的js文件
  • 处理其他文件都需要相对应的处理器进行处理

1. 安装依赖

cnpm install style-loader css-loader less less-loader -D

2. 修改webpack.config.js配置

// webpack.config.js
const path = require('path');

module.exports = {
	mode: 'development',
	entry: './src/index.js',
	output: {
		filename: '[name].js',
		path: path.resolve(__dirname, 'dist')
	},
	module: {
		rules: [
			{
				test: /\.js$/,
				use: {
					loader: 'babel-loader',
					options: {
						presets: ['@babel/preset-env']
					}
				}
			},
			{
				test: /\.css$/,
				use: [
					'style-loader',
					'css-loader'
				]
			},
			{
				test: /\.less$/,
				use: [
					'style-loader',
					'css-loader',
					'less-loader'
				]
			}
		]
	}
	
}

注意

loader的配置有很多能优化的地方


处理图片等静态资源

js文件的其他文件打包,webpack都需要特定的处理器进行处理

1. 安装依赖

npm install url-loader file-loader -D

2. 修改webapck.config.js配置

			{
				test: /\.(jpg|png|jpeg|gif|bmp)$/,
				use: {
					loader: 'url-loader',
					options: {
						limit: 1024,
						fallback: {
							loader: 'file-loader',
							options: {
								name: '[name].[ext]'
							}
						}
					}
				}
			},
			{
				test: /\.(mp4|ogg|mp3|wav)$/,
				use: {
					loader: 'url-loader',
					options: {
						limit:1024,
						fallback: {
							loader: 'file-loader',
							options: {
								name: '[name].[ext]'
							}
						}
					}
				}
			}

创建html文件

令打包的js文件自动插入到html模板中

1. 安装依赖

cnpm install html-webpack-plugin -D

2.修改webpack配置

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
// ...
	plugins: [
		new HtmlWebpackPlugin({
			template: './src/index.html',
			filename: 'index.html',
			title: 'vue3 + TS -> web App'
		})
	]

注意

配置动态网页标题时,需要将模板中的</code>标签里的内容换成<code><%= htmlWebpackPlugin.options.title %></code></p> <ul> <li>此处使用<code>webpack</code>会报错<br> <a href="http://img.e-com-net.com/image/info8/db49f476f1f54cdc9badd3720a973524.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/db49f476f1f54cdc9badd3720a973524.jpg" alt="webpack5部署vue3商业项目详细流程_第4张图片" width="650" height="368" style="border:1px solid black;"></a></li> </ul> <p>结果<br> <a href="http://img.e-com-net.com/image/info8/f93c249d423d4d37b6cbd3d820102edf.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/f93c249d423d4d37b6cbd3d820102edf.png" alt="webpack5部署vue3商业项目详细流程_第5张图片" width="843" height="527" style="border:1px solid black;"></a></p> <ul> <li>使用<code>npm run build</code>则会不同,但是title不会改变<br> <a href="http://img.e-com-net.com/image/info8/2444dd3f6ca34516be9b8f728612a05a.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/2444dd3f6ca34516be9b8f728612a05a.jpg" alt="webpack5部署vue3商业项目详细流程_第6张图片" width="650" height="163" style="border:1px solid black;"></a></li> </ul> <p>结果:没有变成title<br> <a href="http://img.e-com-net.com/image/info8/10f2af6f6e3f4603bb182e03abb959ac.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/10f2af6f6e3f4603bb182e03abb959ac.jpg" alt="webpack5部署vue3商业项目详细流程_第7张图片" width="623" height="218" style="border:1px solid black;"></a></p> <hr> <h2>开发服务器</h2> <p>每次打包后,都需要手动点击<code>dist</code>目录下的<code>index.html</code>看效果,因此,可以设置<code>webpack</code>将打包后的文件自动在浏览器打开</p> <h3>1. 安装依赖</h3> <p><code>cnpm install webpack-dev-server -D</code></p> <h3>2.修改<code>webpack</code>配置</h3> <pre><code class="prism language-javascript">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">//...</span> devServer<span class="token punctuation">:</span> <span class="token punctuation">{</span> port<span class="token punctuation">:</span> <span class="token number">3000</span><span class="token punctuation">,</span> hot<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> open<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> contentBase<span class="token punctuation">:</span> <span class="token string">'../dist'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">//...</span> <span class="token punctuation">}</span> </code></pre> <hr> <h2>清除打包文件</h2> <ul> <li>如果打包的文件加了<code>hash</code>,那每次打包生成的文件都会在<code>dist</code>目录保留</li> <li>我们可以使用此清楚插件在打包前先清理以前的打包文件</li> </ul> <h3>1. 安装依赖</h3> <p><code>cnpm install clean-webpack-plugin -D</code></p> <h3>2.修改<code>webpack</code>配置</h3> <pre><code class="prism language-javascript"><span class="token keyword">const</span> <span class="token punctuation">{</span> CleanWebpackPlugin <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'clean-webpack-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">CleanWebPackPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">]</span> </code></pre> <h3>注意</h3> <ul> <li>此处直接<code>build</code>会报错<br> <a href="http://img.e-com-net.com/image/info8/a31d2f0bde3b483a8fe25df5f272352f.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a31d2f0bde3b483a8fe25df5f272352f.jpg" alt="在这里插入图片描述" width="650" height="85"></a></li> </ul> <hr> <h2>设置环境变量</h2> <h3>设置环境变量常见方式</h3> <ol> <li>命令式</li> <li>配置式</li> <li>创建<code>.env</code>文件</li> <li><code>cross-env</code></li> </ol> <h3>设置</h3> <p>以<code>cross-env</code>的方式来设置环境变量:可以跨终端进行设置</p> <ol> <li>安装依赖<br> <code>cnpm install cross-env -D</code></li> <li>修改<code>package.json</code>配置</li> </ol> <pre><code class="prism language-javascript"> <span class="token string">"scripts"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token string">"build"</span><span class="token punctuation">:</span> <span class="token string">"webpack"</span><span class="token punctuation">,</span> <span class="token string">"webpack"</span><span class="token punctuation">:</span> <span class="token string">"cross-env NODE_ENV=development webpack"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> </code></pre> <hr> <h2>分环境打包</h2> <ul> <li>在平时项目开发中,会分为三种环境: <ol> <li>开发环境</li> <li>测试环境</li> <li>生产环境</li> </ol> </li> <li>如何配置一个多环境打包?</li> </ul> <h3>打包压缩</h3> <p>开发一个项目的最终要求就是要达到功能完备的情况下,打包体积最小,保证用户体验</p> <h4>1. 压缩<code>html</code>文件</h4> <pre><code>- 修改`webpack`配置 </code></pre> <pre><code class="prism language-javascript"><span class="token keyword">const</span> HtmlWebpackPlugin <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'html-webpack-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">HtmlWebpackPlugin</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token comment">// ...</span> <span class="token operator">+</span> minify<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token operator">+</span> collapseWhitespace<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 去掉空格</span> <span class="token operator">+</span> removeComments<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token comment">// 去掉注释</span> <span class="token operator">+</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> <h4>2. 压缩<code>css</code>文件</h4> <pre><code>1. 安装依赖 </code></pre> <p><code>cnpm install mini-css-extract-plugin optimize-css-assets-webpack-plugin -D</code><br> 2. 修改<code>webpack</code>配置文件</p> <pre><code class="prism language-javascript"><span class="token keyword">const</span> MiniCssExtractPlugin <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'mini-css-extract-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> OptimizeCssAssetsWebpackPlugin <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'optimize-css-assets-webpack-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> module<span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token comment">// ...</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.css$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span> MiniCssExtractPlugin<span class="token punctuation">.</span>loader<span class="token punctuation">,</span> <span class="token string">'css-loader'</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.less$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span> MiniCssExtractPlugin<span class="token punctuation">.</span>loader<span class="token punctuation">,</span> <span class="token string">'css-loader'</span><span class="token punctuation">,</span> <span class="token string">'less-loader'</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token comment">// ...</span> <span class="token keyword">new</span> <span class="token class-name">OptimizeCssAssetsWebpackPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">MiniCssExtractPlugin</span><span class="token punctuation">(</span><span class="token punctuation">{</span> filename<span class="token punctuation">:</span> <span class="token string">'css/[name].css'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> <h5>注意</h5> <p><code>purgecss-webpack-plugin</code>用于清除无用的<code>css</code></p> <h4>3. 压缩<code>js</code>文件</h4> <pre><code>1. 安装依赖 </code></pre> <p><code>cnpm install terser-webpack-plugin -D</code><br> 2. 修改<code>webpack</code>配置</p> <pre><code class="prism language-javascript"><span class="token keyword">const</span> TerserWebpackPlugin <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'terser-webpack-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> optimization<span class="token punctuation">:</span> <span class="token punctuation">{</span> minimize<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> minimizer<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">TerserWebpackPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">}</span> </code></pre> <h5>注意</h5> <p><code>uglifyjs-webpack-plugin</code>不支持压缩<code>ES6</code>语法的代码</p> <h4>4. 压缩图片</h4> <ol> <li>安装依赖<br> <code>cnpm install image-webpack-loader -D</code></li> <li>修改<code>webpack</code>文件</li> </ol> <pre><code class="prism language-javascript">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> module<span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token comment">// ...</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.(jpg|png|jpeg|gif|bmp)$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> loader<span class="token punctuation">:</span> <span class="token string">'url-loader'</span><span class="token punctuation">,</span> options<span class="token punctuation">:</span> <span class="token punctuation">{</span> limit<span class="token punctuation">:</span> <span class="token number">1024</span><span class="token punctuation">,</span> fallback<span class="token punctuation">:</span> <span class="token punctuation">{</span> loader<span class="token punctuation">:</span> <span class="token string">'file-loader'</span><span class="token punctuation">,</span> options<span class="token punctuation">:</span> <span class="token punctuation">{</span> name<span class="token punctuation">:</span> <span class="token string">'[name].[ext]'</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> loader<span class="token punctuation">:</span> <span class="token string">'image-webpack-loader'</span><span class="token punctuation">,</span> options<span class="token punctuation">:</span> <span class="token punctuation">{</span> mozjpeg<span class="token punctuation">:</span> <span class="token punctuation">{</span> progressive<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> optipng<span class="token punctuation">:</span> <span class="token punctuation">{</span> enabled<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> pngquant<span class="token punctuation">:</span> <span class="token punctuation">{</span> quality<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token number">0.65</span><span class="token punctuation">,</span> <span class="token number">0.90</span><span class="token punctuation">]</span><span class="token punctuation">,</span> speed<span class="token punctuation">:</span> <span class="token number">4</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> gifsicle<span class="token punctuation">:</span> <span class="token punctuation">{</span> interlaced<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> webp<span class="token punctuation">:</span> <span class="token punctuation">{</span> quality<span class="token punctuation">:</span> <span class="token number">75</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">}</span> </code></pre> <h5>注意</h5> <p>在安装<code>image-webpack-loader</code>依赖时,采用<code>cnpm</code>安装,<code>npm</code>会报错</p> <hr> <h1>集成TypeScript</h1> <hr> <ul> <li>前端工程师必备技能:<code>TypeScript</code></li> <li><code>Vue3</code>源码全部采用<code>TS</code>重写</li> <li>需要掌握的核心概念:泛型、枚举、接口、类、函数等等</li> </ul> <h2>配置环境</h2> <h3>1. 安装依赖</h3> <p><code>cnpm install typescript ts-loader -D</code></p> <h3>2. 修改<code>webpack</code>配置</h3> <pre><code class="prism language-typescript"><span class="token keyword">module</span><span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> <span class="token keyword">module</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.ts$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">'ts-loader'</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">}</span> </code></pre> <h3>3. 初始化<code>tsconfig.json</code>文件</h3> <p><code>tsc --init</code></p> <h3>注意</h3> <p><code>tsc --init</code>报错没有此命令时,需要先在全局安装<code>npm install -g typescript</code><br> 安装成功:<br> <a href="http://img.e-com-net.com/image/info8/737dc72272b945c98987324c102236a3.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/737dc72272b945c98987324c102236a3.png" alt="在这里插入图片描述" width="631" height="90"></a></p> <h2>重点内容</h2> <ul> <li>泛型</li> <li>接口</li> <li>函数</li> <li>……</li> </ul> <hr> <h1>识别<code>.Vue</code>文件</h1> <hr> <h2>1. 安装依赖</h2> <p><code>cnpm install vue@next -S</code><br> <code>cnpm install vue-loader@next @vue/compiler-sfc</code></p> <h3>注意</h3> <p>如果使用的是<code>Vue2.x</code>,需要安装的是<code>vue-template-complier</code></p> <h2>2. 修改<code>webpack</code>文件</h2> <pre><code class="prism language-javascript"><span class="token keyword">const</span> <span class="token punctuation">{</span> VueLoaderPlugin <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'vue-loader/dist/index'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> module<span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.vue$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">'vue-loader'</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">VueLoaderPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> <h2>3. <code>index.js</code>文件中引入<code>vue</code></h2> <pre><code class="prism language-javscript">import { createApp } from 'vue'; import App from './App.vue'; createApp(App).mount('#app') </code></pre> <p>新增<code>App.vue</code>文件</p> <pre><code class="prism language-vue">//App.vue <template> <div> <div>解析vue文件</div> <p>{{name}}</p> </div> </template> <script> import { defineComponent, ref } from 'vue'; export default defineComponent({ setup() { const name = ref('txm'); return { name } } }) </script> </code></pre> <h3>注意</h3> <p><code>defineComponent</code>只是为了在使用<code>vue3</code>时有会很好的语法提示</p> <h2>Composition API</h2> <ul> <li><code>vue3</code>受到<code>React Hooks</code>的启发,将以前的<code>options API</code>改写成<code>函数式API</code></li> <li>优点是将代码进行解耦便于<code>tree-shaking</code>,提高代码的复用率</li> </ul> <h3>vue2缺失</h3> <ul> <li><code>Minxin</code>可以完成公共逻辑代码的抽离,但是<code>Mixin</code>存在诸多缺点</li> <li>命名冲突、同名的方法和计算属性会被覆盖、同名的生命周期都会执行且<code>minxin</code>里的先执行等等</li> </ul> <h3>常用的<code>Composition API</code></h3> <ul> <li>reactive</li> <li>ref</li> <li>effect</li> <li>watch</li> <li>compited</li> <li>生命周期</li> <li>h函数</li> <li>toRefs</li> <li>……</li> </ul> <h3>深入推荐阅读</h3> <ul> <li>Vue 组合式API</li> </ul> <h3>响应式系统</h3> <ul> <li><code>vue2.x</code>的响应式底层核心是采用<code>Object.defineProperty</code>来劫持对象的每个属性的<code>getter</code>和<code>setter</code>,方法是<code>defineReactive</code></li> <li>在获取属性时做依赖收集</li> <li>在更新属性时触发更新</li> </ul> <h4><code>vue2.x</code>核心原理</h4> <pre><code class="prism language-javascript"><span class="token comment">// src\core\observer\index.js</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>Array<span class="token punctuation">.</span><span class="token function">isArray</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">observeArray</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">walk</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token comment">// 处理对象</span> <span class="token function">walk</span> <span class="token punctuation">(</span>obj<span class="token punctuation">:</span> Object<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">const</span> keys <span class="token operator">=</span> Object<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> keys<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token function">defineReactive</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> keys<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token comment">// 处理数组</span> <span class="token function">observeArray</span> <span class="token punctuation">(</span>items<span class="token punctuation">:</span> Array<span class="token operator"><</span>any<span class="token operator">></span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">,</span> l <span class="token operator">=</span> items<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i <span class="token operator"><</span> l<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token function">observe</span><span class="token punctuation">(</span>items<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">defineReactive</span> <span class="token punctuation">(</span> obj<span class="token punctuation">:</span> Object<span class="token punctuation">,</span> key<span class="token punctuation">:</span> string<span class="token punctuation">,</span> val<span class="token punctuation">:</span> any<span class="token punctuation">,</span> customSetter<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token operator">?</span>Function<span class="token punctuation">,</span> shallow<span class="token operator">?</span><span class="token punctuation">:</span> boolean <span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">const</span> dep <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Dep</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">let</span> childOb <span class="token operator">=</span> <span class="token operator">!</span>shallow <span class="token operator">&&</span> <span class="token function">observe</span><span class="token punctuation">(</span>val<span class="token punctuation">)</span> Object<span class="token punctuation">.</span><span class="token function">defineProperty</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> key<span class="token punctuation">,</span> <span class="token punctuation">{</span> enumerable<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> configurable<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token keyword">get</span><span class="token punctuation">:</span> <span class="token keyword">function</span> <span class="token function">reactiveGetter</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">const</span> value <span class="token operator">=</span> getter <span class="token operator">?</span> getter<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token punctuation">:</span> val <span class="token keyword">if</span> <span class="token punctuation">(</span>Dep<span class="token punctuation">.</span>target<span class="token punctuation">)</span> <span class="token punctuation">{</span> dep<span class="token punctuation">.</span><span class="token function">depend</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// 收集依赖</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>childOb<span class="token punctuation">)</span> <span class="token punctuation">{</span> childOb<span class="token punctuation">.</span>dep<span class="token punctuation">.</span><span class="token function">depend</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>Array<span class="token punctuation">.</span><span class="token function">isArray</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token function">dependArray</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> value <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token keyword">set</span><span class="token punctuation">:</span> <span class="token keyword">function</span> <span class="token function">reactiveSetter</span> <span class="token punctuation">(</span>newVal<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">const</span> value <span class="token operator">=</span> getter <span class="token operator">?</span> getter<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token punctuation">:</span> val <span class="token keyword">if</span> <span class="token punctuation">(</span>setter<span class="token punctuation">)</span> <span class="token punctuation">{</span> setter<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> newVal<span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> val <span class="token operator">=</span> newVal <span class="token punctuation">}</span> childOb <span class="token operator">=</span> <span class="token operator">!</span>shallow <span class="token operator">&&</span> <span class="token function">observe</span><span class="token punctuation">(</span>newVal<span class="token punctuation">)</span> dep<span class="token punctuation">.</span><span class="token function">notify</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// 通知更新</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <ul> <li>处理<code>array</code>和<code>Object</code>时,进行判断,然后分别处理</li> <li>如果多层结构直接进行<code>递归</code>操作,且对象每个属性都劫持,性能会变差</li> </ul> <h4><code>vue2.x</code>总结</h4> <p>缺点:</p> <ul> <li>对象属性的新增和删除无法检测。 解决办法:<code>Vue.$set</code>和<code>Vue.delete()</code></li> <li>修改数组的索引和<code>length</code>属性无法检测 解决办法:<code>splice</code></li> </ul> <h4><code>Vue3</code>核心原理</h4> <p>采用了<code>proxy</code>作为底层响应式的核心<code>API</code></p> <pre><code class="prism language-javascript"><span class="token comment">// packages\reactivity\src\reactive.ts</span> <span class="token keyword">function</span> <span class="token function">createReactiveObject</span><span class="token punctuation">(</span> target<span class="token punctuation">:</span> Target<span class="token punctuation">,</span> isReadonly<span class="token punctuation">:</span> boolean<span class="token punctuation">,</span> baseHandlers<span class="token punctuation">:</span> ProxyHandler<span class="token operator"><</span>any<span class="token operator">></span><span class="token punctuation">,</span> collectionHandlers<span class="token punctuation">:</span> ProxyHandler<span class="token operator"><</span>any<span class="token operator">></span> <span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">const</span> proxy <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Proxy</span><span class="token punctuation">(</span> target<span class="token punctuation">,</span> targetType <span class="token operator">===</span> TargetType<span class="token punctuation">.</span><span class="token constant">COLLECTION</span> <span class="token operator">?</span> collectionHandlers <span class="token punctuation">:</span> baseHandlers <span class="token punctuation">)</span> <span class="token keyword">return</span> proxy <span class="token punctuation">}</span> </code></pre> <h3><code>vue3</code>总结</h3> <ul> <li><code>createReactiveObject</code>方法是创建响应式的核心方法</li> <li><code>proxy</code>直接监听整个对象,没有对数组和对象进行分开处理<br> 注意:</li> <li>学习源码时,需要掌握好<code>set</code>, <code>weakset</code>, <code>map</code>, <code>weakmap</code>, <code>reflect</code>等<code>ES6</code>的新特性</li> </ul> <hr> <h1>集成 <code>Vue-Router</code></h1> <hr> <h2>基本使用</h2> <h3>1. 安装依赖</h3> <p><code>npm install vue-router@4 -S</code></p> <h3>2. 创建<code>Home.vue</code>和<code>Me.vue</code></h3> <pre><code class="prism language-vue">// Home.vue // Home.vue <template> <div> 首页 </div> </template> <script> import { defineComponent, ref } from "vue"; export default { name: 'Home' } </script> // Me.vue // Me.vue <template> <div> 我的页面 </div> </template> <script> import { defineComponent, ref } from 'vue'; export default { name: 'Me' } </script> </code></pre> <h3>3. 创建<code>router.js</code>文件</h3> <pre><code class="prism language-javascript"><span class="token keyword">import</span> <span class="token punctuation">{</span> createRouter<span class="token punctuation">,</span> createWebHistory <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"vue-router"</span><span class="token punctuation">;</span> <span class="token keyword">import</span> Home <span class="token keyword">from</span> <span class="token string">'./Home.vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> Me <span class="token keyword">from</span> <span class="token string">'./Me.vue'</span><span class="token punctuation">;</span> <span class="token keyword">const</span> routerHistory <span class="token operator">=</span> <span class="token function">createWebHistory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> router <span class="token operator">=</span> <span class="token function">createRouter</span><span class="token punctuation">(</span><span class="token punctuation">{</span> history<span class="token punctuation">:</span> routerHistory<span class="token punctuation">,</span> routes<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> path<span class="token punctuation">:</span> <span class="token string">'/home'</span><span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token string">'Home'</span><span class="token punctuation">,</span> component<span class="token punctuation">:</span> Home <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> path<span class="token punctuation">:</span> <span class="token string">'/me'</span><span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token string">'Me'</span><span class="token punctuation">,</span> component<span class="token punctuation">:</span> Me <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">export</span> <span class="token keyword">default</span> router<span class="token punctuation">;</span> </code></pre> <h3>4. 修改<code>index.js</code>文件</h3> <pre><code class="prism language-javascript">console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'test webpack'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> App <span class="token keyword">from</span> <span class="token string">'./App.vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> router <span class="token keyword">from</span> <span class="token string">'./router.js'</span><span class="token punctuation">;</span> <span class="token function">createApp</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>router<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">mount</span><span class="token punctuation">(</span><span class="token string">'#app'</span><span class="token punctuation">)</span> </code></pre> <hr> <h1>集成Vuex</h1> <hr> <h2>基本使用</h2> <h3>1. 安装依赖</h3> <p><code>cnpm install vuex@next -S</code></p> <h3>2. 创建<code>store.js</code>文件</h3> <pre><code class="prism language-javscript">import { createStore } from "vuex"; const store = createStore({ state: { name: 'vuex' }, getters: {}, actions: {}, mutations: {}, modules: {} }); export default store; </code></pre> <h3>3. 修改<code>index.js</code>文件</h3> <pre><code class="prism language-javascript">console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'test webpack'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> App <span class="token keyword">from</span> <span class="token string">'./App.vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> router <span class="token keyword">from</span> <span class="token string">'./router.js'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> store <span class="token keyword">from</span> <span class="token string">"./store.js"</span><span class="token punctuation">;</span> <span class="token function">createApp</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>router<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>store<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">mount</span><span class="token punctuation">(</span><span class="token string">'#app'</span><span class="token punctuation">)</span> </code></pre> <h3>4. 在<code>App.vue</code>中获取<code>vuex</code>中的数据</h3> <pre><code class="prism language-javascript"><span class="token operator"><</span>template<span class="token operator">></span> <span class="token operator"><</span>div<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">!</span><span class="token operator">--</span> <span class="token operator">...</span> <span class="token operator">--</span><span class="token operator">></span> <span class="token operator"><</span>p<span class="token operator">></span>获取vuex里面的数据<span class="token punctuation">{</span><span class="token punctuation">{</span>count<span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator"><</span><span class="token operator">/</span>p<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">!</span><span class="token operator">--</span> <span class="token operator">...</span> <span class="token operator">--</span><span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>div<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>template<span class="token operator">></span> <span class="token operator"><</span>script<span class="token operator">></span> <span class="token keyword">import</span> <span class="token punctuation">{</span> defineComponent<span class="token punctuation">,</span> computed <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> <span class="token punctuation">{</span> useStore <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vuex'</span><span class="token punctuation">;</span> <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token function">defineComponent</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">const</span> store <span class="token operator">=</span> <span class="token function">useStore</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> count <span class="token operator">=</span> <span class="token function">computed</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> store<span class="token punctuation">.</span>state<span class="token punctuation">.</span>count<span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token punctuation">{</span> count <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token operator"><</span><span class="token operator">/</span>script<span class="token operator">></span> </code></pre> <h4>注意</h4> <ol> <li>用<code>computed</code>从<code>store</code>中获取数据,保证数据的响应式</li> <li>不熟悉,推荐阅读:Vue3快速入门</li> </ol> <hr> <h1>集成Vant</h1> <hr> <h2>1.安装依赖</h2> <p><code>cnpm install vant@next -S</code></p> <h2>2.按需引入</h2> <h3>1. 依赖</h3> <p><code>cnpm i babel-plugin-import ts-import-plugin -D</code></p> <h3>2.修改配置</h3> <pre><code class="prism language-javascript"><span class="token operator">></span> <span class="token constant">JS</span> <span class="token comment">// babel.config.js</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">[</span> <span class="token string">'import'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> libraryName<span class="token punctuation">:</span> <span class="token string">'vant'</span><span class="token punctuation">,</span> libraryDirectory<span class="token punctuation">:</span> <span class="token string">'es'</span><span class="token punctuation">,</span> style<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">'vant'</span><span class="token punctuation">,</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <blockquote> <p>TS</p> </blockquote> <pre><code class="prism language-typescript"><span class="token keyword">const</span> tsImportPluginFactory <span class="token operator">=</span> <span class="token keyword">require</span><span class="token punctuation">(</span><span class="token string">'ts-import-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">module</span><span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> <span class="token keyword">module</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.ts$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> loader<span class="token punctuation">:</span> <span class="token string">'ts-loader'</span><span class="token punctuation">,</span> options<span class="token punctuation">:</span> <span class="token punctuation">{</span> transpileOnly<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> getCustomTransformers<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">(</span><span class="token punctuation">{</span> before<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token function">tsImportPluginFactory</span><span class="token punctuation">(</span><span class="token punctuation">{</span> libraryName<span class="token punctuation">:</span> <span class="token string">'vant'</span><span class="token punctuation">,</span> libraryDirectory<span class="token punctuation">:</span> <span class="token string">'es'</span><span class="token punctuation">,</span> style<span class="token punctuation">:</span> <span class="token punctuation">(</span>name<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token template-string"><span class="token string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">/style/less`</span></span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span> compilerOptions<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token keyword">module</span><span class="token punctuation">:</span> <span class="token string">'es2015'</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> exclude<span class="token punctuation">:</span> <span class="token regex">/node_modules/</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <hr> <h1>Rem布局适配</h1> <hr> <h2>1. 安装依赖</h2> <p><code>cnpm install lib-flexible -S</code><br> <code>cnpm install postcss-pxtorem -D</code></p> <h2>2. 添加<code>.postcssrc.js</code></h2> <pre><code class="prism language-javascript">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> plugins<span class="token punctuation">:</span><span class="token punctuation">{</span> <span class="token comment">// autoprefixer: {</span> <span class="token comment">// browsers: ['Android >= 4.0', 'iOS >= 8']</span> <span class="token comment">// },</span> <span class="token string">'postcss-pxtorem'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token comment">// rootValue: 37.5, // Vant 官方根字体大小是 37.5</span> <span class="token function">rootValue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>file<span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> file<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">'vant'</span><span class="token punctuation">)</span> <span class="token operator">!==</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token operator">?</span> <span class="token number">37.5</span> <span class="token punctuation">:</span> <span class="token number">75</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> propList<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'*'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> selectorBlackList<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'.norem'</span><span class="token punctuation">]</span> <span class="token comment">// 过滤掉.norem-开头的class,不进行rem转换</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> </code></pre> <h3>注意</h3> <p>browsers 选项需配置在 package.json,不然打包会有警告</p> <pre><code class="prism language-json"><span class="token comment">// package.json</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> <span class="token string">"browserslist"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">"> 1%"</span><span class="token punctuation">,</span> <span class="token string">"last 2 versions"</span><span class="token punctuation">,</span> <span class="token string">"not dead"</span><span class="token punctuation">,</span> <span class="token string">"Android >= 4.0"</span><span class="token punctuation">,</span> <span class="token string">"iOS >= 8"</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> <h2>3. 引入和使用</h2> <pre><code class="prism language-javascript"><span class="token comment">// index.js</span> <span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span><span class="token punctuation">;</span> <span class="token operator">+</span> <span class="token keyword">import</span> <span class="token string">'lib-flexible/flexible'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> App <span class="token keyword">from</span> <span class="token string">'./App.vue'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> router <span class="token keyword">from</span> <span class="token string">'./router.js'</span><span class="token punctuation">;</span> <span class="token keyword">import</span> store <span class="token keyword">from</span> <span class="token string">'./store.js'</span><span class="token punctuation">;</span> <span class="token function">createApp</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>router<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>store<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">mount</span><span class="token punctuation">(</span><span class="token string">'#app'</span><span class="token punctuation">)</span> <span class="token comment">// Home.vue</span> <span class="token operator"><</span>template<span class="token operator">></span> <span class="token operator"><</span>div<span class="token operator">></span> 首页 <span class="token operator"><</span>v<span class="token operator">-</span>button plain hairline type<span class="token operator">=</span><span class="token string">"primary"</span><span class="token operator">></span>细边框按钮<span class="token operator"><</span><span class="token operator">/</span>v<span class="token operator">-</span>button<span class="token operator">></span> <span class="token operator"><</span>v<span class="token operator">-</span>button plain hairline type<span class="token operator">=</span><span class="token string">"primary"</span><span class="token operator">></span>细边框按钮<span class="token operator"><</span><span class="token operator">/</span>v<span class="token operator">-</span>button<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>div<span class="token operator">></span> <span class="token operator"><</span><span class="token operator">/</span>template<span class="token operator">></span> <span class="token operator"><</span>script<span class="token operator">></span> <span class="token keyword">import</span> <span class="token punctuation">{</span> defineComponent<span class="token punctuation">,</span> ref <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"vue"</span><span class="token punctuation">;</span> <span class="token keyword">import</span> <span class="token punctuation">{</span> Button <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"vant"</span><span class="token punctuation">;</span> <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token function">defineComponent</span><span class="token punctuation">(</span><span class="token punctuation">{</span> name<span class="token punctuation">:</span> <span class="token string">"Home"</span><span class="token punctuation">,</span> components<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token string">"v-button"</span><span class="token punctuation">:</span> Button <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator"><</span><span class="token operator">/</span>script<span class="token operator">></span> </code></pre> <hr> <h1>优化</h1> <hr> <ul> <li>项目的重点部分</li> <li>保证功能完整的情况下,打包体积大大缩小<br> 常见优化手段:</li> </ul> <h2>1. 规划目录结构</h2> <p><code>webpack5</code>将各个环境配置好后,规范一下项目的目录结构<br> <code>tree -I "node_modules"</code></p> <pre><code class="prism language-shell">├─dist │ ├─css │ └─js <span class="token operator">|</span> <span class="token operator">|</span>-favicon.ico <span class="token operator">|</span> <span class="token operator">|</span>-index.html ├─node_modules ├─public <span class="token operator">|</span> <span class="token operator">|</span>-index.html <span class="token operator">|</span> <span class="token operator">|</span>-favicon.ico └─src <span class="token operator">|</span> ├─api <span class="token operator">|</span> ├─components <span class="token operator">|</span> ├─hooks <span class="token operator">|</span> ├─router <span class="token operator">|</span> ├─store <span class="token operator">|</span> ├─utils <span class="token operator">|</span> └─views <span class="token operator">|</span> <span class="token operator">|</span>-App.vue <span class="token operator">|</span> <span class="token operator">|</span>-main.ts <span class="token operator">|</span>-.gitigore <span class="token operator">|</span>-babel.config.js <span class="token operator">|</span>-package.json <span class="token operator">|</span>-shims-vue.d.ts <span class="token operator">|</span>-tsconfig.json <span class="token operator">|</span>-webpack.config.js </code></pre> <ul> <li>此目录类似<code>vue</code>脚手架生成的项目目录</li> </ul> <h3>注意</h3> <p>由于<code>typescript</code>只能理解<code>.ts</code>文件,无法理解<code>.vue</code>文件,需要在根目录创建一个后缀名为<code>.d.ts</code>文件</p> <pre><code class="prism language-javascript"><span class="token comment">// shims-vue.d.ts</span> declare module <span class="token string">'*.vue'</span> <span class="token punctuation">{</span> <span class="token keyword">import</span> <span class="token punctuation">{</span> ComponentOptions <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span><span class="token punctuation">;</span> <span class="token keyword">const</span> componentOptions<span class="token punctuation">:</span> ComponentOptions<span class="token punctuation">;</span> <span class="token keyword">export</span> <span class="token keyword">default</span> componentOptions<span class="token punctuation">;</span> <span class="token punctuation">}</span> </code></pre> <h2>2. 打包友好提示</h2> <h3>1. 安装依赖</h3> <p><code>cnpm install friendly-errors-webapck-plugin node-notifier -D</code></p> <h3>2.修改<code>webpack</code>配置</h3> <pre><code class="prism language-js"><span class="token keyword">const</span> path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'path'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">+</span> <span class="token keyword">const</span> FriendlyErrorsWebpackPlugin <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'friendly-errors-webpack-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">+</span> <span class="token keyword">const</span> notifier <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'node-notifier'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">+</span> <span class="token keyword">const</span> icon <span class="token operator">=</span> path<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span>__dirname<span class="token punctuation">,</span> <span class="token string">'public/icon.jpg'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">FriendlyErrorsWebpackPlugin</span><span class="token punctuation">(</span><span class="token punctuation">{</span> onErrors<span class="token punctuation">:</span> <span class="token punctuation">(</span>severity<span class="token punctuation">,</span> errors<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> notifier<span class="token punctuation">.</span><span class="token function">notify</span><span class="token punctuation">(</span><span class="token punctuation">{</span> title<span class="token punctuation">:</span> <span class="token string">'webpack 编译失败了~'</span><span class="token punctuation">,</span> message<span class="token punctuation">:</span> <span class="token template-string"><span class="token string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>severity<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>errors<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span><span class="token punctuation">,</span> subtitle<span class="token punctuation">:</span> errors<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>file <span class="token operator">||</span> <span class="token string">''</span><span class="token punctuation">,</span> icon<span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <h2>3. 分析打包文件大小</h2> <h3>1. 依赖</h3> <p><code>cnpm install webpack-bundle-analyzer -D</code></p> <h3>2. 修改<code>webpack</code>配置</h3> <pre><code class="prism language-js"><span class="token operator">+</span> <span class="token keyword">const</span> <span class="token punctuation">{</span> BundleAnalyzerPlugin <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'webpack-bundle-analyzer'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">BundleAnalyzerPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <h3>3. 修改<code>package.json</code></h3> <pre><code class="prism language-json"><span class="token punctuation">{</span> <span class="token string">"scripts"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> <span class="token string">"analyzer"</span><span class="token punctuation">:</span> <span class="token string">"webpack --progress"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> </code></pre> <h4>技巧</h4> <ul> <li>控制台执行<code>npm run analyzer</code>,系统自动启动打包报告的HTTP服务器</li> <li>不想启动,可以生成<code>state.json</code>文件,后续查看</li> </ul> <pre><code class="prism language-javascript"><span class="token operator">+</span> <span class="token keyword">const</span> <span class="token punctuation">{</span> BundleAnalyzerPlugin <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'webpack-bundle-analyzer'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token keyword">new</span> <span class="token class-name">BundleAnalyzerPlugin</span><span class="token punctuation">(</span><span class="token punctuation">{</span> analyzerMode<span class="token punctuation">:</span> <span class="token string">'disabled'</span><span class="token punctuation">,</span> generateStatsFile<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <ul> <li><code>package.json</code></li> </ul> <pre><code class="prism language-json"><span class="token punctuation">{</span> <span class="token string">"scripts"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> <span class="token operator">+</span> <span class="token string">"analyzers"</span><span class="token punctuation">:</span> <span class="token string">"webpack-bundle-analyzer --port 3000 ./dist/stats.json"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> </code></pre> <ul> <li>通过打包报告可以很直观的知道哪些依赖包大,则可以做做针对性的修改。</li> </ul> <h2>4. 打包速度</h2> <p>此插件可以直观显示每个依赖打包所花费的时间</p> <h3>1.安装依赖</h3> <p><code>cnpm install speed-measure-webpack5-plugin -D</code></p> <h4>注意</h4> <ul> <li><code>webpack5</code>配置此包会报错<br> <a href="http://img.e-com-net.com/image/info8/98b0cddfd4274d35b5091a27fda0a14b.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/98b0cddfd4274d35b5091a27fda0a14b.jpg" alt="在这里插入图片描述" width="650" height="97"></a></li> </ul> <h3>2. 修改<code>webpack</code>配置</h3> <pre><code class="prism language-js"><span class="token keyword">const</span> SpeedMeasureWebpack5Plugin <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'speed-measure-webpack5-plugin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> smw <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SpeedMeasureWebpack5Plugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token function">smw</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token comment">// options</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> </code></pre> <h2>5.缩小打包范围</h2> <ul> <li>exclude:排除某些文件,类似黑名单</li> <li>include:包含文件,类似白名单</li> <li>优先度:exclude >>> include</li> </ul> <pre><code class="prism language-js"><span class="token keyword">const</span> path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'path'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> module<span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.js$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">{</span> loader<span class="token punctuation">:</span> <span class="token string">'babel-loader'</span><span class="token punctuation">,</span> options<span class="token punctuation">:</span> <span class="token punctuation">{</span> presets<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'@babel/preset-env'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> exclude<span class="token punctuation">:</span> <span class="token regex">/node_modules/</span><span class="token punctuation">,</span> include<span class="token punctuation">:</span> path<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>__dirname<span class="token punctuation">,</span> <span class="token string">'src'</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <h2>6. 缓存</h2> <ul> <li>默认<code>babel-loader</code>中可以配置缓存</li> <li>其他<code>loader</code>如果要缓存,需要下载<code>cache-loader</code></li> </ul> <h3>1. 安装依赖</h3> <p><code>cnpm install cache-loader -D</code></p> <h3>2. 修改<code>webpack</code>配置</h3> <pre><code class="prism language-js"><span class="token keyword">const</span> path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'path'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token comment">// ...</span> module<span class="token punctuation">:</span> <span class="token punctuation">{</span> rules<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.js$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">{</span> loader<span class="token punctuation">:</span> <span class="token string">'babel-loader'</span><span class="token punctuation">,</span> options<span class="token punctuation">:</span> <span class="token punctuation">{</span> presets<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'@babel/preset-env'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token operator">+</span> cacheDirectory<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// ...</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> test<span class="token punctuation">:</span> <span class="token regex">/\.css$/</span><span class="token punctuation">,</span> use<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'cache-loader'</span><span class="token punctuation">,</span> <span class="token string">'style-loader'</span><span class="token punctuation">,</span> <span class="token string">'css-loader'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> <span class="token comment">// ...</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <h3>其他</h3> <ul> <li>resolve</li> <li>external</li> <li>optimization</li> <li>等等</li> </ul> <hr> <h1>统一代码规范</h1> <hr> <p>统一代码规范:</p> <ul> <li>代码校验</li> <li>代码格式化</li> <li><code>git</code>提交前校验</li> <li>编辑器配置</li> </ul> <h2>Eslint</h2> <p>代码检查工具</p> <ol> <li>新增<code>.eslintrc.js</code></li> </ol> <pre><code class="prism language-js">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> root<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 此项是用来告诉eslint找当前配置文件不能往父级查找</span> env<span class="token punctuation">:</span> <span class="token punctuation">{</span> node<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 此项指定环境的全局变量,下面的配置指定为node环境</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token keyword">extends</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'plugin:vue/recommended'</span><span class="token punctuation">,</span> <span class="token string">'@vue/prettier'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> rules<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token string">'no-console'</span><span class="token punctuation">:</span> process<span class="token punctuation">.</span>env<span class="token punctuation">.</span><span class="token constant">NODE_ENV</span> <span class="token operator">===</span> <span class="token string">'production'</span> <span class="token operator">?</span> <span class="token string">'warn'</span> <span class="token punctuation">:</span> <span class="token string">'off'</span><span class="token punctuation">,</span> <span class="token string">'no-debugger'</span><span class="token punctuation">:</span> process<span class="token punctuation">.</span>env<span class="token punctuation">.</span><span class="token constant">NODE_ENV</span> <span class="token operator">===</span> <span class="token string">'production'</span> <span class="token operator">?</span> <span class="token string">'warn'</span> <span class="token punctuation">:</span> <span class="token string">'off'</span><span class="token punctuation">,</span> <span class="token string">'vue/no-v-html'</span><span class="token punctuation">:</span> <span class="token string">'off'</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> parserOptions<span class="token punctuation">:</span> <span class="token punctuation">{</span> parser<span class="token punctuation">:</span> <span class="token string">'babel-eslint'</span><span class="token punctuation">,</span> parser<span class="token punctuation">:</span> <span class="token string">'babel-eslint'</span><span class="token punctuation">,</span> ecmaVersion<span class="token punctuation">:</span> <span class="token number">7</span><span class="token punctuation">,</span> sourceType<span class="token punctuation">:</span> <span class="token string">'module'</span><span class="token punctuation">,</span> ecmaFeatures<span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token comment">// 添加ES特性支持,使之能够识别ES6语法</span> jsx<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> overrides<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre> <ol start="2"> <li>新增<code>.eslintignore</code>文件</li> </ol> <pre><code class="prism language-yaml"><span class="token comment"># .eslintignore 不需要检查的文件</span> src/assets src/icons public dist node_modules </code></pre> <h2>Perttier</h2> <p>代码格式化工具</p> <ol> <li>新增<code>prettier.config.js</code>文件</li> </ol> <pre><code class="prism language-js">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> printWidth<span class="token punctuation">:</span> <span class="token number">80</span><span class="token punctuation">,</span> tabWidth<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span> useTabs<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> semi<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> singleQuote<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> quoteProps<span class="token punctuation">:</span> <span class="token string">'as-needed'</span><span class="token punctuation">,</span> jsxSingleQuote<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> trailingComma<span class="token punctuation">:</span> <span class="token string">'es5'</span><span class="token punctuation">,</span> bracketSpacing<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> jsxBracketSameLine<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> arrowParens<span class="token punctuation">:</span> <span class="token string">'always'</span><span class="token punctuation">,</span> htmlWhitespaceSensitivity<span class="token punctuation">:</span> <span class="token string">'ignore'</span><span class="token punctuation">,</span> vueIndentScriptAndStyle<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> endOfLine<span class="token punctuation">:</span> <span class="token string">'lf'</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> </code></pre> <h2>stylelint</h2> <p>规范化<code>css</code>的书写,风格统一,减少错误</p> <ol> <li>新增 <code>.stylelintrc.js</code> 文件</li> </ol> <pre><code class="prism language-js">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token keyword">extends</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'stylelint-config-recess-order'</span><span class="token punctuation">,</span> <span class="token string">'stylelint-config-prettier'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span> </code></pre> <h2>EditorConfig</h2> <ol> <li>新增<code>.editorconfig</code>文件</li> </ol> <pre><code class="prism language-json">root <span class="token operator">=</span> <span class="token boolean">true</span> <span class="token punctuation">[</span><span class="token operator">*</span><span class="token punctuation">]</span> charset <span class="token operator">=</span> utf<span class="token operator">-</span><span class="token number">8</span> end_of_line <span class="token operator">=</span> lf indent_size <span class="token operator">=</span> <span class="token number">2</span> indent_style <span class="token operator">=</span> space insert_final_newline <span class="token operator">=</span> <span class="token boolean">true</span> trim_trailing_whitespace <span class="token operator">=</span> <span class="token boolean">true</span> <span class="token punctuation">[</span><span class="token operator">*</span><span class="token punctuation">.</span>md<span class="token punctuation">]</span> trim_trailing_whitespace <span class="token operator">=</span> <span class="token boolean">false</span> </code></pre> <hr> <h1>配置Git Message</h1> <hr> <h2>1. 依赖</h2> <pre><code class="prism language-shell"><span class="token function">npm</span> <span class="token function">install</span> -g commitizen cz-conventional-changelog <span class="token keyword">echo</span> <span class="token string">'{ "path": "cz-conventional-changelog" }'</span> <span class="token operator">></span> ~/.czrc </code></pre> <ul> <li>安装结束后,可以直接使用<code>git cz</code>来取代<code>git commit</code><br> <code>yarn add husky @commitlint/config-conventional @commitlint/cli -D</code></li> <li><code>commit</code>:负责对<code>commit message</code>进行格式检验</li> <li><code>husky</code>:负责提供更易用的<code>git hook</code></li> </ul> <h2>2. 创建<code>commit.config.js</code></h2> <pre><code class="prism language-shell"><span class="token keyword">echo</span> <span class="token string">'module.exports = {extends: ["@commitlint/config-conventional"]};'</span> <span class="token operator">></span> ./commitlint.config.js </code></pre> <ul> <li><code>utf-8</code>格式,否则报错</li> </ul> <h2>3. <code>package.json</code>文件中引入<code>husky</code></h2> <pre><code class="prism language-json"><span class="token string">"husky"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token string">"hooks"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token string">"commit-msg"</span><span class="token punctuation">:</span> <span class="token string">"commitlint -e $GIT_PARAMS"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <h2>4. 使用</h2> <ul> <li><code>git add .</code></li> <li><code>git cz</code> 选择并输入</li> <li><code>git push -u origin branchname</code></li> </ul> <hr> <p>自动化发布</p> <hr> <p><code>CI/CD</code> 自动化测试发布</p> <pre><code class="prism language-js"><span class="token keyword">let</span> client <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'scp2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> ora <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'ora'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> chalk <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'chalk'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">const</span> spinner <span class="token operator">=</span> <span class="token function">ora</span><span class="token punctuation">(</span>chalk<span class="token punctuation">.</span><span class="token function">green</span><span class="token punctuation">(</span><span class="token string">'正在发布到服务器...'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> spinner<span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span> client<span class="token punctuation">.</span><span class="token function">scp</span><span class="token punctuation">(</span><span class="token string">'./dist'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token comment">// 本地打包的路径</span> <span class="token string">'host'</span><span class="token punctuation">:</span> <span class="token string">'xxx.xxx.x.xxx'</span><span class="token punctuation">,</span> <span class="token comment">// 服务器的IP地址</span> <span class="token string">'post'</span><span class="token punctuation">:</span> <span class="token string">'22'</span><span class="token punctuation">,</span> <span class="token comment">// 服务器的IP地址</span> <span class="token string">'username'</span><span class="token punctuation">:</span> <span class="token string">'xxxx'</span><span class="token punctuation">,</span> <span class="token comment">// 用户名</span> <span class="token string">'password'</span><span class="token punctuation">:</span> <span class="token string">'*****'</span><span class="token punctuation">,</span> <span class="token comment">// 密码</span> <span class="token string">'path'</span><span class="token punctuation">:</span> <span class="token string">'/opt/stu_app_website'</span> <span class="token comment">// 项目需要部署到服务器的位置</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> err <span class="token operator">=></span> <span class="token punctuation">{</span> spinner<span class="token punctuation">.</span><span class="token function">stop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>err<span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>chalk<span class="token punctuation">.</span><span class="token function">green</span><span class="token punctuation">(</span><span class="token string">'项目发布完毕'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'err'</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> </code></pre> <hr> <p>总结</p> <hr> <ul> <li>熟悉整体流程</li> <li>自我提升</li> </ul> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1642832994190286848"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(WEB,javascript,vue.js,typescript,前端,webpack)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1835512920797179904.htm" title="element实现动态路由+面包屑" target="_blank">element实现动态路由+面包屑</a> <span class="text-muted">软件技术NINI</span> <a class="tag" taget="_blank" href="/search/vue%E6%A1%88%E4%BE%8B/1.htm">vue案例</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>el-breadcrumb是ElementUI组件库中的一个面包屑导航组件,它用于显示当前页面的路径,帮助用户快速理解和导航到应用的各个部分。在Vue.js项目中,如果你已经安装了ElementUI,就可以很方便地使用el-breadcrumb组件。以下是一个基本的使用示例:安装ElementUI(如果你还没有安装的话):你可以通过npm或yarn来安装ElementUI。bash复制代码npmi</div> </li> <li><a href="/article/1835511912843014144.htm" title="理解Gunicorn:Python WSGI服务器的基石" target="_blank">理解Gunicorn:Python WSGI服务器的基石</a> <span class="text-muted">范范0825</span> <a class="tag" taget="_blank" href="/search/ipython/1.htm">ipython</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a> <div>理解Gunicorn:PythonWSGI服务器的基石介绍Gunicorn,全称GreenUnicorn,是一个为PythonWSGI(WebServerGatewayInterface)应用设计的高效、轻量级HTTP服务器。作为PythonWeb应用部署的常用工具,Gunicorn以其高性能和易用性著称。本文将介绍Gunicorn的基本概念、安装和配置,帮助初学者快速上手。1.什么是Gunico</div> </li> <li><a href="/article/1835509897106649088.htm" title="Long类型前后端数据不一致" target="_blank">Long类型前后端数据不一致</a> <span class="text-muted">igotyback</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>响应给前端的数据浏览器控制台中response中看到的Long类型的数据是正常的到前端数据不一致前后端数据类型不匹配是一个常见问题,尤其是当后端使用Java的Long类型(64位)与前端JavaScript的Number类型(最大安全整数为2^53-1,即16位)进行数据交互时,很容易出现精度丢失的问题。这是因为JavaScript中的Number类型无法安全地表示超过16位的整数。为了解决这个问</div> </li> <li><a href="/article/1835504218178416640.htm" title="Google earth studio 简介" target="_blank">Google earth studio 简介</a> <span class="text-muted">陟彼高冈yu</span> <a class="tag" taget="_blank" href="/search/%E6%97%85%E6%B8%B8/1.htm">旅游</a> <div>GoogleEarthStudio是一个基于Web的动画工具,专为创作使用GoogleEarth数据的动画和视频而设计。它利用了GoogleEarth强大的三维地图和卫星影像数据库,使用户能够轻松地创建逼真的地球动画、航拍视频和动态地图可视化。网址为https://www.google.com/earth/studio/。GoogleEarthStudio是一个基于Web的动画工具,专为创作使用G</div> </li> <li><a href="/article/1835502578050363392.htm" title="PHP环境搭建详细教程" target="_blank">PHP环境搭建详细教程</a> <span class="text-muted">好看资源平台</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/php/1.htm">php</a> <div>PHP是一个流行的服务器端脚本语言,广泛用于Web开发。为了使PHP能够在本地或服务器上运行,我们需要搭建一个合适的PHP环境。本教程将结合最新资料,介绍在不同操作系统上搭建PHP开发环境的多种方法,包括Windows、macOS和Linux系统的安装步骤,以及本地和Docker环境的配置。1.PHP环境搭建概述PHP环境的搭建主要分为以下几类:集成开发环境:例如XAMPP、WAMP、MAMP,这</div> </li> <li><a href="/article/1835498925755297792.htm" title="DIV+CSS+JavaScript技术制作网页(旅游主题网页设计与制作)云南大理" target="_blank">DIV+CSS+JavaScript技术制作网页(旅游主题网页设计与制作)云南大理</a> <span class="text-muted">STU学生网页设计</span> <a class="tag" taget="_blank" href="/search/%E7%BD%91%E9%A1%B5%E8%AE%BE%E8%AE%A1/1.htm">网页设计</a><a class="tag" taget="_blank" href="/search/%E6%9C%9F%E6%9C%AB%E7%BD%91%E9%A1%B5%E4%BD%9C%E4%B8%9A/1.htm">期末网页作业</a><a class="tag" taget="_blank" href="/search/html%E9%9D%99%E6%80%81%E7%BD%91%E9%A1%B5/1.htm">html静态网页</a><a class="tag" taget="_blank" href="/search/html5%E6%9C%9F%E6%9C%AB%E5%A4%A7%E4%BD%9C%E4%B8%9A/1.htm">html5期末大作业</a><a class="tag" taget="_blank" href="/search/%E7%BD%91%E9%A1%B5%E8%AE%BE%E8%AE%A1/1.htm">网页设计</a><a class="tag" taget="_blank" href="/search/web%E5%A4%A7%E4%BD%9C%E4%B8%9A/1.htm">web大作业</a> <div>️精彩专栏推荐作者主页:【进入主页—获取更多源码】web前端期末大作业:【HTML5网页期末作业(1000套)】程序员有趣的告白方式:【HTML七夕情人节表白网页制作(110套)】文章目录二、网站介绍三、网站效果▶️1.视频演示2.图片演示四、网站代码HTML结构代码CSS样式代码五、更多源码二、网站介绍网站布局方面:计划采用目前主流的、能兼容各大主流浏览器、显示效果稳定的浮动网页布局结构。网站程</div> </li> <li><a href="/article/1835497792265613312.htm" title="【加密社】Solidity 中的事件机制及其应用" target="_blank">【加密社】Solidity 中的事件机制及其应用</a> <span class="text-muted">加密社</span> <a class="tag" taget="_blank" href="/search/%E9%97%B2%E4%BE%83/1.htm">闲侃</a><a class="tag" taget="_blank" href="/search/%E5%8C%BA%E5%9D%97%E9%93%BE/1.htm">区块链</a><a class="tag" taget="_blank" href="/search/%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6/1.htm">智能合约</a><a class="tag" taget="_blank" href="/search/%E5%8C%BA%E5%9D%97%E9%93%BE/1.htm">区块链</a> <div>加密社引言在Solidity合约开发过程中,事件(Events)是一种非常重要的机制。它们不仅能够让开发者记录智能合约的重要状态变更,还能够让外部系统(如前端应用)监听这些状态的变化。本文将详细介绍Solidity中的事件机制以及如何利用不同的手段来触发、监听和获取这些事件。事件存储的地方当我们在Solidity合约中使用emit关键字触发事件时,该事件会被记录在区块链的交易收据中。具体而言,事件</div> </li> <li><a href="/article/1835496149843275776.htm" title="关于城市旅游的HTML网页设计——(旅游风景云南 5页)HTML+CSS+JavaScript" target="_blank">关于城市旅游的HTML网页设计——(旅游风景云南 5页)HTML+CSS+JavaScript</a> <span class="text-muted">二挡起步</span> <a class="tag" taget="_blank" href="/search/web%E5%89%8D%E7%AB%AF%E6%9C%9F%E6%9C%AB%E5%A4%A7%E4%BD%9C%E4%B8%9A/1.htm">web前端期末大作业</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a><a class="tag" taget="_blank" href="/search/%E6%97%85%E6%B8%B8/1.htm">旅游</a><a class="tag" taget="_blank" href="/search/%E9%A3%8E%E6%99%AF/1.htm">风景</a> <div>⛵源码获取文末联系✈Web前端开发技术描述网页设计题材,DIV+CSS布局制作,HTML+CSS网页设计期末课程大作业|游景点介绍|旅游风景区|家乡介绍|等网站的设计与制作|HTML期末大学生网页设计作业,Web大学生网页HTML:结构CSS:样式在操作方面上运用了html5和css3,采用了div+css结构、表单、超链接、浮动、绝对定位、相对定位、字体样式、引用视频等基础知识JavaScrip</div> </li> <li><a href="/article/1835496148601761792.htm" title="HTML网页设计制作大作业(div+css) 云南我的家乡旅游景点 带文字滚动" target="_blank">HTML网页设计制作大作业(div+css) 云南我的家乡旅游景点 带文字滚动</a> <span class="text-muted">二挡起步</span> <a class="tag" taget="_blank" href="/search/web%E5%89%8D%E7%AB%AF%E6%9C%9F%E6%9C%AB%E5%A4%A7%E4%BD%9C%E4%B8%9A/1.htm">web前端期末大作业</a><a class="tag" taget="_blank" href="/search/web%E8%AE%BE%E8%AE%A1%E7%BD%91%E9%A1%B5%E8%A7%84%E5%88%92%E4%B8%8E%E8%AE%BE%E8%AE%A1/1.htm">web设计网页规划与设计</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/dreamweaver/1.htm">dreamweaver</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>Web前端开发技术描述网页设计题材,DIV+CSS布局制作,HTML+CSS网页设计期末课程大作业游景点介绍|旅游风景区|家乡介绍|等网站的设计与制作HTML期末大学生网页设计作业HTML:结构CSS:样式在操作方面上运用了html5和css3,采用了div+css结构、表单、超链接、浮动、绝对定位、相对定位、字体样式、引用视频等基础知识JavaScript:做与用户的交互行为文章目录前端学习路线</div> </li> <li><a href="/article/1835495170972413952.htm" title="git - Webhook让部署自动化" target="_blank">git - Webhook让部署自动化</a> <span class="text-muted">大猪大猪</span> <div>我们现在有一个需求,将项目打包上传到gitlab或者github后,程序能自动部署,不用手动地去服务器中进行项目更新并运行,如何做到?这里我们可以使用gitlab与github的挂钩,挂钩的原理就是,每当我们有请求到gitlab与github服务器时,这时他俩会根据我们配置的挂钩地扯进行访问,webhook挂钩程序会一直监听着某个端口请求,一但收到他们发过来的请求,这时就知道用户有请求提交了,这时</div> </li> <li><a href="/article/1835493267907637248.htm" title="webpack图片等资源的处理" target="_blank">webpack图片等资源的处理</a> <span class="text-muted">dmengmeng</span> <div>需要的loaderfile-loader(让我们可以引入这些资源文件)url-loader(其实是file-loader的二次封装)img-loader(处理图片所需要的)在没有使用任何处理图片的loader之前,比如说css中用到了背景图片,那么最后打包会报错的,因为他没办法处理图片。其实你只想能够使用图片的话。只加一个file-loader就可以,打开网页能准确看到图片。{test:/\.(p</div> </li> <li><a href="/article/1835492740536823808.htm" title="node.js学习" target="_blank">node.js学习</a> <span class="text-muted">小猿L</span> <a class="tag" taget="_blank" href="/search/node.js/1.htm">node.js</a><a class="tag" taget="_blank" href="/search/node.js/1.htm">node.js</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a><a class="tag" taget="_blank" href="/search/vim/1.htm">vim</a> <div>node.js学习实操及笔记温故node.js,node.js学习实操过程及笔记~node.js学习视频node.js官网node.js中文网实操笔记githubcsdn笔记为什么学node.js可以让别人访问我们编写的网页为后续的框架学习打下基础,三大框架vuereactangular离不开node.jsnode.js是什么官网:node.js是一个开源的、跨平台的运行JavaScript的运行</div> </li> <li><a href="/article/1835470931783413760.htm" title="「豆包Marscode体验官」 | 云端 IDE 启动 & Rust 体验" target="_blank">「豆包Marscode体验官」 | 云端 IDE 启动 & Rust 体验</a> <span class="text-muted">张风捷特烈</span> <a class="tag" taget="_blank" href="/search/ide/1.htm">ide</a><a class="tag" taget="_blank" href="/search/rust/1.htm">rust</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>theme:cyanosis我正在参加「豆包MarsCode初体验」征文活动MarsCode可以看作一个运行在服务端的远程VSCode开发环境。对于我这种想要学习体验某些语言,但不想在电脑里装环境的人来说非常友好。本文就来介绍一下在MarsCode里,我的体验rust开发体验。一、MarsCode是什么它的本质是:提供代码助手和云端IDE服务的web网站,可通过下面的链接访问https://www</div> </li> <li><a href="/article/1835455048277127168.htm" title="Python神器!WEB自动化测试集成工具 DrissionPage" target="_blank">Python神器!WEB自动化测试集成工具 DrissionPage</a> <span class="text-muted">亚丁号</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>一、前言用requests做数据采集面对要登录的网站时,要分析数据包、JS源码,构造复杂的请求,往往还要应付验证码、JS混淆、签名参数等反爬手段,门槛较高。若数据是由JS计算生成的,还须重现计算过程,体验不好,开发效率不高。使用浏览器,可以很大程度上绕过这些坑,但浏览器运行效率不高。因此,这个库设计初衷,是将它们合而为一,能够在不同须要时切换相应模式,并提供一种人性化的使用方法,提高开发和运行效率</div> </li> <li><a href="/article/1835454921990828032.htm" title="Java爬虫框架(一)--架构设计" target="_blank">Java爬虫框架(一)--架构设计</a> <span class="text-muted">狼图腾-狼之传说</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%A1%86%E6%9E%B6/1.htm">框架</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E4%BB%BB%E5%8A%A1/1.htm">任务</a><a class="tag" taget="_blank" href="/search/html%E8%A7%A3%E6%9E%90%E5%99%A8/1.htm">html解析器</a><a class="tag" taget="_blank" href="/search/%E5%AD%98%E5%82%A8/1.htm">存储</a><a class="tag" taget="_blank" href="/search/%E7%94%B5%E5%AD%90%E5%95%86%E5%8A%A1/1.htm">电子商务</a> <div>一、架构图那里搜网络爬虫框架主要针对电子商务网站进行数据爬取,分析,存储,索引。爬虫:爬虫负责爬取,解析,处理电子商务网站的网页的内容数据库:存储商品信息索引:商品的全文搜索索引Task队列:需要爬取的网页列表Visited表:已经爬取过的网页列表爬虫监控平台:web平台可以启动,停止爬虫,管理爬虫,task队列,visited表。二、爬虫1.流程1)Scheduler启动爬虫器,TaskMast</div> </li> <li><a href="/article/1835454543471669248.htm" title="Java:爬虫框架" target="_blank">Java:爬虫框架</a> <span class="text-muted">dingcho</span> <a class="tag" taget="_blank" href="/search/Java/1.htm">Java</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a> <div>一、ApacheNutch2【参考地址】Nutch是一个开源Java实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。包括全文搜索和Web爬虫。Nutch致力于让每个人能很容易,同时花费很少就可以配置世界一流的Web搜索引擎.为了完成这一宏伟的目标,Nutch必须能够做到:每个月取几十亿网页为这些网页维护一个索引对索引文件进行每秒上千次的搜索提供高质量的搜索结果简单来说Nutch支持分</div> </li> <li><a href="/article/1835451016456269824.htm" title="MongoDB知识概括" target="_blank">MongoDB知识概括</a> <span class="text-muted">GeorgeLin98</span> <a class="tag" taget="_blank" href="/search/%E6%8C%81%E4%B9%85%E5%B1%82/1.htm">持久层</a><a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a> <div>MongoDB知识概括MongoDB相关概念单机部署基本常用命令索引-IndexSpirngDataMongoDB集成副本集分片集群安全认证MongoDB相关概念业务应用场景:传统的关系型数据库(如MySQL),在数据操作的“三高”需求以及应对Web2.0的网站需求面前,显得力不从心。解释:“三高”需求:①Highperformance-对数据库高并发读写的需求。②HugeStorage-对海量数</div> </li> <li><a href="/article/1835448238103162880.htm" title="springboot+vue项目实战一-创建SpringBoot简单项目" target="_blank">springboot+vue项目实战一-创建SpringBoot简单项目</a> <span class="text-muted">苹果酱0567</span> <a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95%E9%A2%98%E6%B1%87%E6%80%BB%E4%B8%8E%E8%A7%A3%E6%9E%90/1.htm">面试题汇总与解析</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>这段时间抽空给女朋友搭建一个个人博客,想着记录一下建站的过程,就当做笔记吧。虽然复制zjblog只要一个小时就可以搞定一个网站,或者用cms系统,三四个小时就可以做出一个前后台都有的网站,而且想做成啥样也都行。但是就是要从新做,自己做的意义不一样,更何况,俺就是专门干这个的,嘿嘿嘿要做一个网站,而且从零开始,首先呢就是技术选型了,经过一番思量决定选择-SpringBoot做后端,前端使用Vue做一</div> </li> <li><a href="/article/1835448239864770560.htm" title="JavaScript 中,深拷贝(Deep Copy)和浅拷贝(Shallow Copy)" target="_blank">JavaScript 中,深拷贝(Deep Copy)和浅拷贝(Shallow Copy)</a> <span class="text-muted">跳房子的前端</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF%E9%9D%A2%E8%AF%95/1.htm">前端面试</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/ecmascript/1.htm">ecmascript</a> <div>在JavaScript中,深拷贝(DeepCopy)和浅拷贝(ShallowCopy)是用于复制对象或数组的两种不同方法。了解它们的区别和应用场景对于避免潜在的bugs和高效地处理数据非常重要。以下是对深拷贝和浅拷贝的详细解释,包括它们的概念、用途、优缺点以及实现方式。1.浅拷贝(ShallowCopy)概念定义:浅拷贝是指创建一个新的对象或数组,其中包含了原对象或数组的基本数据类型的值和对引用数</div> </li> <li><a href="/article/1835443823287824384.htm" title="Python实现下载当前年份的谷歌影像" target="_blank">Python实现下载当前年份的谷歌影像</a> <span class="text-muted">sand&wich</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>在GIS项目和地图应用中,获取最新的地理影像数据是非常重要的。本文将介绍如何使用Python代码从Google地图自动下载当前年份的影像数据,并将其保存为高分辨率的TIFF格式文件。这个过程涉及地理坐标转换、多线程下载和图像处理。关键功能该脚本的核心功能包括:坐标转换:支持WGS-84与WebMercator投影之间转换,以及处理中国GCJ-02偏移。自动化下载:多线程下载地图瓦片,提高效率。图像</div> </li> <li><a href="/article/1835443569968640000.htm" title="Spring MVC 全面指南:从入门到精通的详细解析" target="_blank">Spring MVC 全面指南:从入门到精通的详细解析</a> <span class="text-muted">一杯梅子酱</span> <a class="tag" taget="_blank" href="/search/%E6%8A%80%E6%9C%AF%E6%A0%88%E5%AD%A6%E4%B9%A0/1.htm">技术栈学习</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/mvc/1.htm">mvc</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>引言:SpringMVC,作为Spring框架的一个重要模块,为构建Web应用提供了强大的功能和灵活性。无论是初学者还是有一定经验的开发者,掌握SpringMVC都将显著提升你的Web开发技能。本文旨在为初学者提供一个全面且易于理解的学习路径,通过详细的知识点分析和实际案例,帮助你快速上手SpringMVC,让学习过程既深刻又高效。一、SpringMVC简介1.1什么是SpringMVC?Spri</div> </li> <li><a href="/article/1835438028768768000.htm" title="Spring Boot中实现跨域请求" target="_blank">Spring Boot中实现跨域请求</a> <span class="text-muted">BABA8891</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>在SpringBoot中实现跨域请求(CORS,Cross-OriginResourceSharing)可以通过多种方式,以下是几种常见的方法:1.使用@CrossOrigin注解在SpringBoot中,你可以在控制器或者具体的请求处理方法上使用@CrossOrigin注解来允许跨域请求。在控制器上应用:importorg.springframework.web.bind.annotation.</div> </li> <li><a href="/article/1835438028009598976.htm" title="WebMagic:强大的Java爬虫框架解析与实战" target="_blank">WebMagic:强大的Java爬虫框架解析与实战</a> <span class="text-muted">Aaron_945</span> <a class="tag" taget="_blank" href="/search/Java/1.htm">Java</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>文章目录引言官网链接WebMagic原理概述基础使用1.添加依赖2.编写PageProcessor高级使用1.自定义Pipeline2.分布式抓取优点结论引言在大数据时代,网络爬虫作为数据收集的重要工具,扮演着不可或缺的角色。Java作为一门广泛使用的编程语言,在爬虫开发领域也有其独特的优势。WebMagic是一个开源的Java爬虫框架,它提供了简单灵活的API,支持多线程、分布式抓取,以及丰富的</div> </li> <li><a href="/article/1835437775344726016.htm" title="博客网站制作教程" target="_blank">博客网站制作教程</a> <span class="text-muted">2401_85194651</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a> <div>首先就是技术框架:后端:Java+SpringBoot数据库:MySQL前端:Vue.js数据库连接:JPA(JavaPersistenceAPI)1.项目结构blog-app/├──backend/│├──src/main/java/com/example/blogapp/││├──BlogApplication.java││├──config/│││└──DatabaseConfig.java</div> </li> <li><a href="/article/1835435506645692416.htm" title="00. 这里整理了最全的爬虫框架(Java + Python)" target="_blank">00. 这里整理了最全的爬虫框架(Java + Python)</a> <span class="text-muted">有一只柴犬</span> <a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB%E7%B3%BB%E5%88%97/1.htm">爬虫系列</a><a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>目录1、前言2、什么是网络爬虫3、常见的爬虫框架3.1、java框架3.1.1、WebMagic3.1.2、Jsoup3.1.3、HttpClient3.1.4、Crawler4j3.1.5、HtmlUnit3.1.6、Selenium3.2、Python框架3.2.1、Scrapy3.2.2、BeautifulSoup+Requests3.2.3、Selenium3.2.4、PyQuery3.2</div> </li> <li><a href="/article/1835428948339683328.htm" title="JavaScript `Map` 和 `WeakMap`详细解释" target="_blank">JavaScript `Map` 和 `WeakMap`详细解释</a> <span class="text-muted">跳房子的前端</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/%E5%8E%9F%E7%94%9F%E6%96%B9%E6%B3%95/1.htm">原生方法</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>在JavaScript中,Map和WeakMap都是用于存储键值对的数据结构,但它们有一些关键的不同之处。MapMap是一种可以存储任意类型的键值对的集合。它保持了键值对的插入顺序,并且可以通过键快速查找对应的值。Map提供了一些非常有用的方法和属性来操作这些数据对:set(key,value):将一个键值对添加到Map中。如果键已经存在,则更新其对应的值。get(key):获取指定键的值。如果键</div> </li> <li><a href="/article/1835428317084348416.htm" title="最简单将静态网页挂载到服务器上(不用nginx)" target="_blank">最简单将静态网页挂载到服务器上(不用nginx)</a> <span class="text-muted">全能全知者</span> <a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/nginx/1.htm">nginx</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/%E7%AC%94%E8%AE%B0/1.htm">笔记</a> <div>最简单将静态网页挂载到服务器上(不用nginx)如果随便弄个静态网页挂在服务器都要用nignx就太麻烦了,所以直接使用Apache来搭建一些简单前端静态网页会相对方便很多检查Web服务器服务状态:sudosystemctlstatushttpd#ApacheWeb服务器如果发现没有安装web服务器:安装Apache:sudoyuminstallhttpd启动Apache:sudosystemctl</div> </li> <li><a href="/article/1835427057752961024.htm" title="补充元象二面" target="_blank">补充元象二面</a> <span class="text-muted">Redstone Monstrosity</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a> <div>1.请尽可能详细地说明,防抖和节流的区别,应用场景?你的回答中不要写出示例代码。防抖(Debounce)和节流(Throttle)是两种常用的前端性能优化技术,它们的主要区别在于如何处理高频事件的触发。以下是防抖和节流的区别和应用场景的详细说明:防抖和节流的定义防抖:在一段时间内,多次执行变为只执行最后一次。防抖的原理是,当事件被触发后,设置一个延迟定时器。如果在这个延迟时间内事件再次被触发,则重</div> </li> <li><a href="/article/1835420753252675584.htm" title="微信小程序开发注意事项" target="_blank">微信小程序开发注意事项</a> <span class="text-muted">jun778895</span> <a class="tag" taget="_blank" href="/search/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/1.htm">微信小程序</a><a class="tag" taget="_blank" href="/search/%E5%B0%8F%E7%A8%8B%E5%BA%8F/1.htm">小程序</a> <div>微信小程序开发是一个融合了前端开发、用户体验设计、后端服务(可选)以及微信小程序平台特性的综合性项目。这里,我将详细介绍一个典型的小程序开发项目的全过程,包括项目规划、设计、开发、测试及部署上线等各个环节,并尽量使内容达到或超过2000字的要求。一、项目规划1.1项目背景与目标假设我们要开发一个名为“智慧校园助手”的微信小程序,旨在为学生提供一站式校园生活服务,包括课程表查询、图书馆座位预约、食堂</div> </li> <li><a href="/article/1835419870070665216.htm" title="切换淘宝最新npm镜像源是" target="_blank">切换淘宝最新npm镜像源是</a> <span class="text-muted">hai40587</span> <a class="tag" taget="_blank" href="/search/npm/1.htm">npm</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/node.js/1.htm">node.js</a> <div>切换淘宝最新npm镜像源是一个相对简单的过程,但首先需要明确当前淘宝npm镜像源的状态和最新的镜像地址。由于网络环境和服务更新,镜像源的具体地址可能会发生变化,因此,我将基于当前可获取的信息,提供一个通用的切换步骤,并附上最新的镜像地址(截至回答时)。一、了解npm镜像源npm(NodePackageManager)是JavaScript的包管理器,用于安装、更新和管理项目依赖。由于npm官方仓库</div> </li> <li><a href="/article/117.htm" title="Algorithm" target="_blank">Algorithm</a> <span class="text-muted">香水浓</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/Algorithm/1.htm">Algorithm</a> <div>冒泡排序 public static void sort(Integer[] param) { for (int i = param.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { int current = param[j]; int next = param[j + 1];</div> </li> <li><a href="/article/244.htm" title="mongoDB 复杂查询表达式" target="_blank">mongoDB 复杂查询表达式</a> <span class="text-muted">开窍的石头</span> <a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a> <div>1:count    Pg: db.user.find().count();    统计多少条数据 2:不等于$ne    Pg: db.user.find({_id:{$ne:3}},{name:1,sex:1,_id:0});    查询id不等于3的数据。 3:大于$gt $gte(大于等于) &n</div> </li> <li><a href="/article/371.htm" title="Jboss Java heap space异常解决方法, jboss OutOfMemoryError : PermGen space" target="_blank">Jboss Java heap space异常解决方法, jboss OutOfMemoryError : PermGen space</a> <span class="text-muted">0624chenhong</span> <a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a><a class="tag" taget="_blank" href="/search/jboss/1.htm">jboss</a> <div>转自 http://blog.csdn.net/zou274/article/details/5552630 解决办法: window->preferences->java->installed jres->edit jre 把default vm arguments 的参数设为-Xms64m -Xmx512m ----------------</div> </li> <li><a href="/article/498.htm" title="文件上传 下载 解析 相对路径" target="_blank">文件上传 下载 解析 相对路径</a> <span class="text-muted">不懂事的小屁孩</span> <a class="tag" taget="_blank" href="/search/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0/1.htm">文件上传</a> <div>有点坑吧,弄这么一个简单的东西弄了一天多,身边还有大神指导着,网上各种百度着。 下面总结一下遇到的问题: 文件上传,在页面上传的时候,不要想着去操作绝对路径,浏览器会对客户端的信息进行保护,避免用户信息收到攻击。 在上传图片,或者文件时,使用form表单来操作。 前台通过form表单传输一个流到后台,而不是ajax传递参数到后台,代码如下: <form action=&</div> </li> <li><a href="/article/625.htm" title="怎么实现qq空间批量点赞" target="_blank">怎么实现qq空间批量点赞</a> <span class="text-muted">换个号韩国红果果</span> <a class="tag" taget="_blank" href="/search/qq/1.htm">qq</a> <div>纯粹为了好玩!! 逻辑很简单 1 打开浏览器console;输入以下代码。 先上添加赞的代码 var tools={}; //添加所有赞 function init(){ document.body.scrollTop=10000; setTimeout(function(){document.body.scrollTop=0;},2000);//加</div> </li> <li><a href="/article/752.htm" title="判断是否为中文" target="_blank">判断是否为中文</a> <span class="text-muted">灵静志远</span> <a class="tag" taget="_blank" href="/search/%E4%B8%AD%E6%96%87/1.htm">中文</a> <div>方法一: public class Zhidao { public static void main(String args[]) { String s = "sdf灭礌 kjl d{';\fdsjlk是"; int n=0; for(int i=0; i<s.length(); i++) { n = (int)s.charAt(i); if((</div> </li> <li><a href="/article/879.htm" title="一个电话面试后总结" target="_blank">一个电话面试后总结</a> <span class="text-muted">a-john</span> <a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a> <div>今天,接了一个电话面试,对于还是初学者的我来说,紧张了半天。 面试的问题分了层次,对于一类问题,由简到难。自己觉得回答不好的地方作了一下总结:   在谈到集合类的时候,举几个常用的集合类,想都没想,直接说了list,map。   然后对list和map分别举几个类型:   list方面:ArrayList,LinkedList。在谈到他们的区别时,愣住了</div> </li> <li><a href="/article/1006.htm" title="MSSQL中Escape转义的使用" target="_blank">MSSQL中Escape转义的使用</a> <span class="text-muted">aijuans</span> <a class="tag" taget="_blank" href="/search/MSSQL/1.htm">MSSQL</a> <div>IF OBJECT_ID('tempdb..#ABC') is not null drop table tempdb..#ABC create table #ABC ( PATHNAME NVARCHAR(50) ) insert into #ABC SELECT N'/ABCDEFGHI' UNION ALL SELECT N'/ABCDGAFGASASSDFA' UNION ALL</div> </li> <li><a href="/article/1133.htm" title="一个简单的存储过程" target="_blank">一个简单的存储过程</a> <span class="text-muted">asialee</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B/1.htm">存储过程</a><a class="tag" taget="_blank" href="/search/%E6%9E%84%E9%80%A0%E6%95%B0%E6%8D%AE/1.htm">构造数据</a><a class="tag" taget="_blank" href="/search/%E6%89%B9%E9%87%8F%E6%8F%92%E5%85%A5/1.htm">批量插入</a> <div>           今天要批量的生成一批测试数据,其中中间有部分数据是变化的,本来想写个程序来生成的,后来想到存储过程就可以搞定,所以随手写了一个,记录在此:            DELIMITER $$ DROP PROCEDURE IF EXISTS inse</div> </li> <li><a href="/article/1260.htm" title="annot convert from HomeFragment_1 to Fragment" target="_blank">annot convert from HomeFragment_1 to Fragment</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/%E5%AF%BC%E5%8C%85%E9%94%99%E8%AF%AF/1.htm">导包错误</a> <div>创建了几个类继承Fragment, 需要将创建的类存储在ArrayList<Fragment>中; 出现不能将new 出来的对象放到队列中,原因很简单;     创建类时引入包是:import android.app.Fragment;      创建队列和对象时使用的包是:import android.support.v4.ap</div> </li> <li><a href="/article/1387.htm" title="Weblogic10两种修改端口的方法" target="_blank">Weblogic10两种修改端口的方法</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/weblogic/1.htm">weblogic</a><a class="tag" taget="_blank" href="/search/%E7%AB%AF%E5%8F%A3%E5%8F%B7/1.htm">端口号</a><a class="tag" taget="_blank" href="/search/%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86/1.htm">配置管理</a><a class="tag" taget="_blank" href="/search/config.xml/1.htm">config.xml</a> <div>一.进入控制台进行修改    1.进入控制台:  http://127.0.0.1:7001/console     2.展开左边树菜单         域结构->环境->服务器-->点击AdminServer(管理) &</div> </li> <li><a href="/article/1514.htm" title="mysql 操作指令" target="_blank">mysql 操作指令</a> <span class="text-muted">征客丶</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>一、连接mysql 进入 mysql 的安装目录; $ bin/mysql -p [host IP 如果是登录本地的mysql 可以不写 -p 直接 -u] -u [userName] -p 输入密码,回车,接连; 二、权限操作[如果你很了解mysql数据库后,你可以直接去修改系统表,然后用 mysql> flush privileges; 指令让权限生效] 1、赋权 mys</div> </li> <li><a href="/article/1641.htm" title="【Hive一】Hive入门" target="_blank">【Hive一】Hive入门</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/hive/1.htm">hive</a> <div>Hive安装与配置 Hive的运行需要依赖于Hadoop,因此需要首先安装Hadoop2.5.2,并且Hive的启动前需要首先启动Hadoop。   Hive安装和配置的步骤   1. 从如下地址下载Hive0.14.0   http://mirror.bit.edu.cn/apache/hive/    2.解压hive,在系统变</div> </li> <li><a href="/article/1768.htm" title="ajax 三种提交请求的方法" target="_blank">ajax 三种提交请求的方法</a> <span class="text-muted">BlueSkator</span> <a class="tag" taget="_blank" href="/search/Ajax/1.htm">Ajax</a><a class="tag" taget="_blank" href="/search/jqery/1.htm">jqery</a> <div>1、ajax 提交请求 $.ajax({ type:"post", url : "${ctx}/front/Hotel/getAllHotelByAjax.do", dataType : "json", success : function(result) { try { for(v</div> </li> <li><a href="/article/1895.htm" title="mongodb开发环境下的搭建入门" target="_blank">mongodb开发环境下的搭建入门</a> <span class="text-muted">braveCS</span> <a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a> <div>  linux下安装mongodb 1)官网下载mongodb-linux-x86_64-rhel62-3.0.4.gz 2)linux 解压  gzip -d mongodb-linux-x86_64-rhel62-3.0.4.gz; mv mongodb-linux-x86_64-rhel62-3.0.4 mongodb-linux-x86_64-rhel62-</div> </li> <li><a href="/article/2022.htm" title="编程之美-最短摘要的生成" target="_blank">编程之美-最短摘要的生成</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B9%8B%E7%BE%8E/1.htm">编程之美</a> <div> import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class ShortestAbstract { /** * 编程之美 最短摘要的生成 * 扫描过程始终保持一个[pBegin,pEnd]的range,初始化确保[pBegin,pEnd]的ran</div> </li> <li><a href="/article/2149.htm" title="json数据解析及typeof" target="_blank">json数据解析及typeof</a> <span class="text-muted">chengxuyuancsdn</span> <a class="tag" taget="_blank" href="/search/js/1.htm">js</a><a class="tag" taget="_blank" href="/search/typeof/1.htm">typeof</a><a class="tag" taget="_blank" href="/search/json%E8%A7%A3%E6%9E%90/1.htm">json解析</a> <div> // json格式 var people='{"authors": [{"firstName": "AAA","lastName": "BBB"},' +' {"firstName": "CCC&</div> </li> <li><a href="/article/2276.htm" title="流程系统设计的层次和目标" target="_blank">流程系统设计的层次和目标</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a><a class="tag" taget="_blank" href="/search/%E6%A1%86%E6%9E%B6/1.htm">框架</a><a class="tag" taget="_blank" href="/search/%E8%84%9A%E6%9C%AC/1.htm">脚本</a> <div>                               流程系统设计的层次和目标  </div> </li> <li><a href="/article/2403.htm" title="RMAN List和report 命令" target="_blank">RMAN List和report 命令</a> <span class="text-muted">daizj</span> <a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/list/1.htm">list</a><a class="tag" taget="_blank" href="/search/report/1.htm">report</a><a class="tag" taget="_blank" href="/search/rman/1.htm">rman</a> <div>LIST 命令 使用RMAN LIST 命令显示有关资料档案库中记录的备份集、代理副本和映像副本的 信息。使用此命令可列出: • RMAN 资料档案库中状态不是AVAILABLE 的备份和副本 • 可用的且可以用于还原操作的数据文件备份和副本 • 备份集和副本,其中包含指定数据文件列表或指定表空间的备份 • 包含指定名称或范围的所有归档日志备份的备份集和副本 • 由标记、完成时间、可</div> </li> <li><a href="/article/2530.htm" title="二叉树:红黑树" target="_blank">二叉树:红黑树</a> <span class="text-muted">dieslrae</span> <a class="tag" taget="_blank" href="/search/%E4%BA%8C%E5%8F%89%E6%A0%91/1.htm">二叉树</a> <div>    红黑树是一种自平衡的二叉树,它的查找,插入,删除操作时间复杂度皆为O(logN),不会出现普通二叉搜索树在最差情况时时间复杂度会变为O(N)的问题.     红黑树必须遵循红黑规则,规则如下     1、每个节点不是红就是黑。     2、根总是黑的  &</div> </li> <li><a href="/article/2657.htm" title="C语言homework3,7个小题目的代码" target="_blank">C语言homework3,7个小题目的代码</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/c/1.htm">c</a> <div>1、打印100以内的所有奇数。 # include <stdio.h> int main(void) { int i; for (i=1; i<=100; i++) { if (i%2 != 0) printf("%d ", i); } return 0; }  2、从键盘上输入10个整数,</div> </li> <li><a href="/article/2784.htm" title="自定义按钮, 图片在上, 文字在下, 居中显示" target="_blank">自定义按钮, 图片在上, 文字在下, 居中显示</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%AE%9A%E4%B9%89/1.htm">自定义</a> <div>#import <UIKit/UIKit.h> @interface MyButton : UIButton -(void)setFrame:(CGRect)frame ImageName:(NSString*)imageName Target:(id)target Action:(SEL)action Title:(NSString*)title Font:(CGFloa</div> </li> <li><a href="/article/2911.htm" title="MySQL查询语句练习题,测试足够用了" target="_blank">MySQL查询语句练习题,测试足够用了</a> <span class="text-muted">flyvszhb</span> <a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a><a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>http://blog.sina.com.cn/s/blog_767d65530101861c.html 1.创建student和score表 CREATE  TABLE  student ( id  INT(10)  NOT NULL  UNIQUE  PRIMARY KEY  , name  VARCHAR</div> </li> <li><a href="/article/3038.htm" title="转:MyBatis Generator 详解" target="_blank">转:MyBatis Generator 详解</a> <span class="text-muted">happyqing</span> <a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a> <div>  MyBatis Generator 详解 http://blog.csdn.net/isea533/article/details/42102297   MyBatis Generator详解 http://git.oschina.net/free/Mybatis_Utils/blob/master/MybatisGeneator/MybatisGeneator.</div> </li> <li><a href="/article/3165.htm" title="让程序员少走弯路的14个忠告" target="_blank">让程序员少走弯路的14个忠告</a> <span class="text-muted">jingjing0907</span> <a class="tag" taget="_blank" href="/search/%E5%B7%A5%E4%BD%9C/1.htm">工作</a><a class="tag" taget="_blank" href="/search/%E8%AE%A1%E5%88%92/1.htm">计划</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a> <div>  无论是谁,在刚进入某个领域之时,有再大的雄心壮志也敌不过眼前的迷茫:不知道应该怎么做,不知道应该做什么。下面是一名软件开发人员所学到的经验,希望能对大家有所帮助   1.不要害怕在工作中学习。 只要有电脑,就可以通过电子阅读器阅读报纸和大多数书籍。如果你只是做好自己的本职工作以及分配的任务,那是学不到很多东西的。如果你盲目地要求更多的工作,也是不可能提升自己的。放</div> </li> <li><a href="/article/3292.htm" title="nginx和NetScaler区别" target="_blank">nginx和NetScaler区别</a> <span class="text-muted">流浪鱼</span> <a class="tag" taget="_blank" href="/search/nginx/1.htm">nginx</a> <div>NetScaler是一个完整的包含操作系统和应用交付功能的产品,Nginx并不包含操作系统,在处理连接方面,需要依赖于操作系统,所以在并发连接数方面和防DoS攻击方面,Nginx不具备优势。 2.易用性方面差别也比较大。Nginx对管理员的水平要求比较高,参数比较多,不确定性给运营带来隐患。在NetScaler常见的配置如健康检查,HA等,在Nginx上的配置的实现相对复杂。 3.策略灵活度方</div> </li> <li><a href="/article/3419.htm" title="第11章 动画效果(下)" target="_blank">第11章 动画效果(下)</a> <span class="text-muted">onestopweb</span> <a class="tag" taget="_blank" href="/search/%E5%8A%A8%E7%94%BB/1.htm">动画</a> <div>index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/</div> </li> <li><a href="/article/3546.htm" title="FAQ - SAP BW BO roadmap" target="_blank">FAQ - SAP BW BO roadmap</a> <span class="text-muted">blueoxygen</span> <a class="tag" taget="_blank" href="/search/BO/1.htm">BO</a><a class="tag" taget="_blank" href="/search/BW/1.htm">BW</a> <div>http://www.sdn.sap.com/irj/boc/business-objects-for-sap-faq   Besides, I care that how to integrate tightly.   By the way, for BW consultants, please just focus on Query Designer which i</div> </li> <li><a href="/article/3673.htm" title="关于java堆内存溢出的几种情况" target="_blank">关于java堆内存溢出的几种情况</a> <span class="text-muted">tomcat_oracle</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a><a class="tag" taget="_blank" href="/search/jdk/1.htm">jdk</a><a class="tag" taget="_blank" href="/search/thread/1.htm">thread</a> <div>【情况一】:    java.lang.OutOfMemoryError: Java heap space:这种是java堆内存不够,一个原因是真不够,另一个原因是程序中有死循环;   如果是java堆内存不够的话,可以通过调整JVM下面的配置来解决:   <jvm-arg>-Xms3062m</jvm-arg>   <jvm-arg>-Xmx</div> </li> <li><a href="/article/3800.htm" title="Manifest.permission_group权限组" target="_blank">Manifest.permission_group权限组</a> <span class="text-muted">阿尔萨斯</span> <a class="tag" taget="_blank" href="/search/Permission/1.htm">Permission</a> <div>结构 继承关系 public static final class Manifest.permission_group extends Object java.lang.Object android. Manifest.permission_group 常量 ACCOUNTS 直接通过统计管理器访问管理的统计 COST_MONEY可以用来让用户花钱但不需要通过与他们直接牵涉的权限 D</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>