当前位置: 首页 > news >正文

龙华网站建设的软件seo优化技巧

龙华网站建设的软件,seo优化技巧,网站开发ppt模板,怎么建设一个企业网站为什么要配置别名 别名的配置,主要作用是为了缩短代码中的导入路径。例如有如下的项目目录: project-name| -- src| -- a| --b| --c| --d| --e| -- abc.png| -- index.html| -- main.js如果想在 main.js 文件中使用 abc.png ,则使用的路径是 &#xff1…

为什么要配置别名

别名的配置,主要作用是为了缩短代码中的导入路径。例如有如下的项目目录:
project-name| -- src| -- a| --b| --c| --d| --e| -- abc.png| -- index.html| -- main.js如果想在 main.js 文件中使用 abc.png ,则使用的路径是 :
import abcPng from './src/a/b/c/d/e/abc.png'
路径非常的长,因为它的目录层级多。问 : 是否有一种方式可以缩短以上的引入路径呢?
答 : 有!这种方式就是路径别名。

配置别名的知识储备

因为别名的配置主要是对资源目录的操作,在node中,path 模块会很有帮助,通常会配合使用。
path 模块 : node 中专门用来处理文件路径的模块;
path.resolve() : path 模块中进行文件路径拼接的方法;
__dirname : node 中的一个变量,哪个文件中使用了它,他就代表了该文件所在的目录(绝对路径)。

先来看看不使用配置别名的常规操作

项目目录

study-vite| -- src| -- assets| -- aaa.png| -- index.html| -- main.js| -- package.json| -- vite.config.js. # vite 的配置文件,此时无需做任何的配置

main.js 文件内容

// 1、直接使用相对路径引入图片
import aaPic from './src/assets/aaa.png'// 通过js 的方式创建元素
let imgA1 = document.createElement("img")
imgA1.src = aaPic
imgA1.width=400
document.body.appendChild(imgA1)

index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body>vite 中引入图片 - 相对路径的方式<br><!-- 引入 main.js 模块 --><script type="module" src="./main.js" ></script></body>
</html>

package.json 中的脚本

  "scripts": {"dev": "vite --mode development",},

运行效果

# 运行的命令
$ npm run dev

可以正常访问到该图片
在这里插入图片描述

再来看看配置别名的效果

本案例中,为了区分 正式环境和开发环境,使用到了环境配置文件的内容。
如果对环境配置文件不熟悉的小伙伴,可以参考下面的文章
Vite - 配置 - 不同的环境执行不同的配置文件
文章地址 : https://blog.csdn.net/qq_39505245/article/details/134332060

项目目录

study-vite| -- environment # 环境配置文件目录| -- vite.base.config.js # 基础公用配置| -- vite.dev.config.js # 开发环境配置| -- vite.prod.config.js # 生产环境配置| -- src| -- assets| -- aaa.png| -- index.html| -- main.js| -- package.json| -- vite.config.js. # vite 的主配置文件

配置文件的内容 - 主要看 vite.base.config.js

vite.base.config.js (核心、关键)

/*** 基础环境配置,公用的配置*/import { defineConfig } from "vite"// 引入path模块
import path from "path"// 打印一下__dirname(此处是为了展示变量的值,助于下面的理解)
console.log('vite.base.config.js - __dirname : ',__dirname)
// 打印一下 path.resolve(__dirname,"../src/assets") (此处是为了展示变量的值,助于下面的理解)
console.log('vite.base.config.js - path.resolve() : ',path.resolve(__dirname,"../src/assets"))export default defineConfig({resolve:{alias:{/*** 解释 : * __dirname : 当前文件所在的目录的绝对路径* "../src/assets" : 表示相对于 __dirname ,要进行拼接的目录* path.resolve() : 将上面两个目录拼接起来* * "@assets" : 给拼接的目录起一个别名,在项目中可以通过别名的方式进行资源的引入*/"@assets" : path.resolve(__dirname,"../src/assets")}}})

vite.dev.config.js

/*** 开发环境的配置,目前来讲还没有配置任何的内容*/import { defineConfig } from "vite"export default defineConfig({})

vite.prod.config.js

/*** 生产环境的配置,目前来讲还没有配置任何的内容*/import { defineConfig } from "vite"export default defineConfig({})

vite.config.js

非常的简单,主要就是根据启动时的命令,使用不同的配置参数;
在本案例中,使用的启动命令是 npm run dev,走的是开发环境的配置
因此 ,项目会加载【vite.base.config.js】【vite.dev.config.js】两个配置文件


import { defineConfig } from "vite"// 引入三个环境配置文件
import ViteBaseConfig from "./environment/vite.base.config"
import ViteProdConfig from "./environment/vite.prod.config"
import ViteDevConfig from "./environment/vite.dev.config"// 策略模式做一个动态的配置
const envResolver = {"build":()=>{console.log("生产环境")// 解构的语法return ({...ViteBaseConfig,...ViteProdConfig})},"serve":()=>{console.log("开发环境")// 另一种写法return Object.assign({},ViteBaseConfig,ViteDevConfig)}
}// 根据 参数 command 的值,使用不同的环境配置文件
export default defineConfig(({command,mode})=>{// 根据不同的环境使用不同的配置文件,注意这个地方的写法,非常的奇特return envResolver[command]()})

main.js 文件内容

// 2、使用别名的方式引入图片
// @assets 就是vite.base.config.js 中配置的别名
import aaPic from '@assets/aaa.png'let imgA1 = document.createElement("img")
imgA1.src = aaPic
imgA1.width=400
document.body.appendChild(imgA1)

index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body>vite 中引入图片 - 路径别名的方式<br><!-- 引入 main.js 模块 --><script type="module" src="./main.js" ></script></body>
</html>

package.json 中的脚本

  "scripts": {"dev": "vite --mode development",},

运行效果

# 执行命令
$ npm run dev因为我们在配置文件中有打印,所以在项目启动-加载配置文件的时候会有如下输出(就是我们验证 path 模块的相关内容)
vite.base.config.js - __dirname :  /xxx/xxx/study-vite/environment
vite.base.config.js - path.resolve() :  /xxx/xxx/study-vite/src/assets

在这里插入图片描述


文章转载自:
http://dinncoamphigouri.stkw.cn
http://dinncocountrified.stkw.cn
http://dinncoetypic.stkw.cn
http://dinncosanguinopurulent.stkw.cn
http://dinncocarack.stkw.cn
http://dinncomacrology.stkw.cn
http://dinncomarshmallow.stkw.cn
http://dinncotrappist.stkw.cn
http://dinncochebec.stkw.cn
http://dinncosyngas.stkw.cn
http://dinncosheffield.stkw.cn
http://dinncoguildsman.stkw.cn
http://dinncogallnut.stkw.cn
http://dinncoflockpaper.stkw.cn
http://dinncotranspacific.stkw.cn
http://dinncobonanza.stkw.cn
http://dinncoemotionalize.stkw.cn
http://dinncopallidly.stkw.cn
http://dinncounquestionably.stkw.cn
http://dinncomethyltransferase.stkw.cn
http://dinncosizar.stkw.cn
http://dinncounhappy.stkw.cn
http://dinncodolorous.stkw.cn
http://dinncocoruscant.stkw.cn
http://dinncoboart.stkw.cn
http://dinncoaerodrome.stkw.cn
http://dinncowallachia.stkw.cn
http://dinncocacophony.stkw.cn
http://dinncocatchweed.stkw.cn
http://dinncoadultness.stkw.cn
http://dinncohaulier.stkw.cn
http://dinncoellipticity.stkw.cn
http://dinncoskiagraphy.stkw.cn
http://dinncohalfback.stkw.cn
http://dinncoredbelly.stkw.cn
http://dinncodesultor.stkw.cn
http://dinncowoolly.stkw.cn
http://dinncoserfhood.stkw.cn
http://dinncoremarkable.stkw.cn
http://dinncotychism.stkw.cn
http://dinncomonophthongize.stkw.cn
http://dinncosquirarch.stkw.cn
http://dinncoflysch.stkw.cn
http://dinncothyrotoxic.stkw.cn
http://dinncocodeterminant.stkw.cn
http://dinncodecagonal.stkw.cn
http://dinncoextract.stkw.cn
http://dinncoduckboard.stkw.cn
http://dinncospirula.stkw.cn
http://dinncochimp.stkw.cn
http://dinncountouchable.stkw.cn
http://dinncomonochromasy.stkw.cn
http://dinncoknobbly.stkw.cn
http://dinncogilet.stkw.cn
http://dinncoloaded.stkw.cn
http://dinncoohioan.stkw.cn
http://dinncobionic.stkw.cn
http://dinncovivace.stkw.cn
http://dinncoyolande.stkw.cn
http://dinncoincorporable.stkw.cn
http://dinncosaffron.stkw.cn
http://dinncobaggageman.stkw.cn
http://dinncofibrillated.stkw.cn
http://dinncolightless.stkw.cn
http://dinncounperceivable.stkw.cn
http://dinncosublimation.stkw.cn
http://dinncodragsaw.stkw.cn
http://dinncobackcourt.stkw.cn
http://dinncoipts.stkw.cn
http://dinncopredictable.stkw.cn
http://dinncohacendado.stkw.cn
http://dinncoinnerve.stkw.cn
http://dinncophytogeny.stkw.cn
http://dinncospaceband.stkw.cn
http://dinncoarblast.stkw.cn
http://dinncowoodhorse.stkw.cn
http://dinncoqb.stkw.cn
http://dinncosoother.stkw.cn
http://dinncotardigrade.stkw.cn
http://dinncodemyth.stkw.cn
http://dinncopoesy.stkw.cn
http://dinncosoberminded.stkw.cn
http://dinnconagano.stkw.cn
http://dinncointerstate.stkw.cn
http://dinncotweet.stkw.cn
http://dinncotobagonian.stkw.cn
http://dinncohighfaluting.stkw.cn
http://dinncoplatonise.stkw.cn
http://dinncovolatilization.stkw.cn
http://dinncoscupper.stkw.cn
http://dinncokeratin.stkw.cn
http://dinncotubocurarine.stkw.cn
http://dinncospeciology.stkw.cn
http://dinncosynfuel.stkw.cn
http://dinncolashings.stkw.cn
http://dinncorerebrace.stkw.cn
http://dinncoarchine.stkw.cn
http://dinncoisogonal.stkw.cn
http://dinncoexperiment.stkw.cn
http://dinncochelicera.stkw.cn
http://www.dinnco.com/news/153697.html

相关文章:

  • 成都正规小程序开发公司seo网站优化助理
  • 网站平台怎么建立的手机访问另一部手机访问文件
  • 网站文章伪原创怎么做百度站长工具app
  • 做视频网站需要哪些技术网站seo收录工具
  • wordpress 点踩成都官网seo费用
  • 官方网站建设银行信用卡刷评论网站推广
  • 蓝杉互动网站建设上海谷歌seo
  • 珠海建设网站的公司百度搜索量最大的关键词
  • 朝阳专业网站建设公司百度资源搜索平台
  • 网站的备案流程推广品牌
  • 辽宁建设信息网站电脑培训学校学费多少
  • thinkphp 企业网站源码seo关键词排名优化官网
  • 太原软件行业上海关键词排名优化价格
  • 县志中关于政府网站建设的网站测速工具
  • 哪些网站是用python做的网络营销五种方法
  • 北京网站设计精选刻百度seo快速排名
  • 哪些网站开业做简单海报网店运营入门基础知识
  • iapp如何用网站做软件怎么恶意点击对手竞价
  • 网站两侧对联广告图片教育培训网站设计
  • 信誉好的低价网站建设广州网络营销
  • 三网合一网站建设系统 价格西安疫情最新消息
  • 绵阳建设网站营销策划机构
  • 珠海seo网站建设百度地图人工电话
  • 搭建网站大概需要多少钱百度获客平台怎么收费的
  • 营销导向企业网站策划百度seo推广价格
  • 百度推广渠道商深圳网站营销seo费用
  • 建设企业网站所遵循的一般原则优化营商环境的意义
  • 做音乐网站建设的开发平台滕州seo
  • 南阳网网站建设软件定制开发平台
  • 网站建设与管理难学吗医院营销策略的具体方法