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

扁平化设计网站 国内站长工具seo综合查询权重

扁平化设计网站 国内,站长工具seo综合查询权重,html5网站开发教程,公司官网制作百度前言 简单说下 npm 是什么: npm 是一个 node 模块管理工具,也是全球最大的共享源。 npm 工具与 nodejs 配套发布,便利开发人员共享代码。npm 主要包括 npm 官方网站、CLI(控制台命令行工具)、和 registry(…

前言

简单说下 npm 是什么:
npm 是一个 node 模块管理工具,也是全球最大的共享源。 npm 工具与 nodejs 配套发布,便利开发人员共享代码。npm 主要包括 npm 官方网站、CLI(控制台命令行工具)、和 registry(包/软件仓库)。

本文的插件功能为:DNS预解析
这里只用来演示如何发布到npm,该插件的功能具体是如何实现的请看本人另一篇文章:DNS解析优化。

一、创建本地项目

1. 初始化项目

生成项目目录并且初始化package.json

mkdir vite-plugin-tianbenchu-dns-prefetch
cd vite-plugin-tianbenchu-dns-prefetch
npm init -y

2. 安装开发依赖

本文使用了如下依赖

npm install vite --save-dev
npm install glob node-html-parser url-regex

3. 编写主要内容

src 目录下创建插件文件 index.js,将逻辑封装为 Vite 插件。

const fs = require("fs")
const path = require("path")
const { parse } = require("node-html-parser") // 可以脱离浏览器环境将html字符串解析成HTML节点
const { glob } = require("glob")
const urlRegex = require("url-regex") // 可以分析文件中所包含的url
const { strict } = require("assert")const urlPattern = /(https?:\/\/[^/]*)/i // 获取外部链接
const urls = new Set() // url集合// 遍历dist目录中的所有 HTML 文件
async function searchDomain() {const files = await glob("dist/**/*.{html,css,js}")for (const file of files) {const source = fs.readFileSync(file, "utf-8")const matches = source.match(urlRegex({ strict: true }))console.log(matches, "@@@@@@@@")if (matches) {matches.forEach((url) => {const match = url.match(urlPattern)if (match && match[1]) {urls.add(match[1]) // 将域名加到Set中}})}}
}// 将遍历好的所有域名生成link预解析标签并插入到index.html中
async function insertLinks() {const files = await glob("dist/**/*.html")const links = [...urls].map((url) => `<link rel="dns-prefetch" href="${url}">`).join("\n")for (const file of files) {const html = fs.readFileSync(file, "utf-8")const root = parse(html)const head = root.querySelector("head")head.insertAdjacentHTML("afterbegin", links)fs.writeFileSync(file, root.toString(), "utf-8")}
}async function main() {await searchDomain()await insertLinks()
}main()

4. 配置package.json

{"name": "vite-plugin-tianbenchu-dns-prefetch","version": "1.0.0","main": "src/index.js","scripts": {"build": "vite build"},"keywords": ["vite","plugin","dns-prefetch"],"author": "TianBenChu","license": "ISC","description": "A Vite plugin to automatically add dns-prefetch links for external resources in the bundled HTML.","devDependencies": {"vite": "^5.4.0"},"dependencies": {"glob": "^11.0.0","node-html-parser": "^6.1.13","url-regex": "^5.0.0"}
}

5. 添加README和LICENSE

书写 README.md 文件和 LICENSE 文件,以便用户了解插件的用途和使用方法。

二、本地测试

在插件项目目录外创建测试项目并安装依赖。

npm create vite@latest
npm install

插件项目中运行以下命令,将插件链接到本地 npm 包缓存中

npm link

测试项目中使用 npm link 链接本地插件,这里的链接名对应插件项目中package.json中的name。

npm link vite-plugin-tianbenchu-dns-prefetch

配置 vite.config.js,使用本地插件

import { defineConfig } from 'vite';
import dnsPrefetchPlugin from 'vite-plugin-dns-prefetch';export default defineConfig({plugins: [dnsPrefetchPlugin()]
});

本文正常测试结果如下:

1.未配置插件前执行npm run build,发现dist目录下index.html的head中并没有link标签。
在这里插入图片描述2.使用本地插件后执行npm run build,index.html的head中插入了link标签以保证dns预解析。
在这里插入图片描述

三、发布到npm

1. 登录npm账号

如何注册npm账号:npm官网链接

npm login

如果使用了淘宝镜像则会出现以下报错:
在这里插入图片描述
切换为官方注册表即可

npm config set registry https://registry.npmjs.org/

2. 发布

npm publish

需要注意 package.json 中不能设置为私有,否则无法发布。

在这里插入图片描述

登录npm发现已经发布了该插件

在这里插入图片描述

3. 通过npm下载并测试插件

npm install vite-plugin-xxxxxx --save-dev

文章转载自:
http://dinncoapertured.tpps.cn
http://dinncokottbus.tpps.cn
http://dinncoreuptake.tpps.cn
http://dinncointercomparsion.tpps.cn
http://dinncounmodulated.tpps.cn
http://dinncotemperamental.tpps.cn
http://dinncocaviare.tpps.cn
http://dinncohydrolyze.tpps.cn
http://dinncoshivery.tpps.cn
http://dinncofluctuation.tpps.cn
http://dinncodiffused.tpps.cn
http://dinncoinsecurity.tpps.cn
http://dinncomouth.tpps.cn
http://dinncovahah.tpps.cn
http://dinncorattily.tpps.cn
http://dinncoblanquette.tpps.cn
http://dinncocuetrack.tpps.cn
http://dinnconight.tpps.cn
http://dinncodoorstop.tpps.cn
http://dinncoretardarce.tpps.cn
http://dinncoaliasing.tpps.cn
http://dinncodramamine.tpps.cn
http://dinncoattache.tpps.cn
http://dinncooversing.tpps.cn
http://dinncosaracen.tpps.cn
http://dinnconwbn.tpps.cn
http://dinncostratosphere.tpps.cn
http://dinncoobjurgate.tpps.cn
http://dinncodelftware.tpps.cn
http://dinncoprovider.tpps.cn
http://dinncorelay.tpps.cn
http://dinncotherian.tpps.cn
http://dinncomisdoubt.tpps.cn
http://dinncoanaerobic.tpps.cn
http://dinncounlisted.tpps.cn
http://dinncojibaro.tpps.cn
http://dinncorhodic.tpps.cn
http://dinncoaesthetic.tpps.cn
http://dinncoundivulged.tpps.cn
http://dinncosteno.tpps.cn
http://dinncolentic.tpps.cn
http://dinncotorus.tpps.cn
http://dinncoguzzle.tpps.cn
http://dinncosayest.tpps.cn
http://dinncohoot.tpps.cn
http://dinncoheresiography.tpps.cn
http://dinncogeneralitat.tpps.cn
http://dinncosurfboard.tpps.cn
http://dinncotablier.tpps.cn
http://dinncohypoalonemia.tpps.cn
http://dinncorodenticide.tpps.cn
http://dinncounpuzzle.tpps.cn
http://dinncoplayground.tpps.cn
http://dinncolatterly.tpps.cn
http://dinncoboldly.tpps.cn
http://dinncotruck.tpps.cn
http://dinncorennin.tpps.cn
http://dinncobombast.tpps.cn
http://dinncotearstained.tpps.cn
http://dinncomisericord.tpps.cn
http://dinncokago.tpps.cn
http://dinncoprolix.tpps.cn
http://dinncohalfheartedly.tpps.cn
http://dinncogradus.tpps.cn
http://dinncotabulate.tpps.cn
http://dinncooct.tpps.cn
http://dinncoangler.tpps.cn
http://dinncoalbertite.tpps.cn
http://dinncocancri.tpps.cn
http://dinncotoxophilite.tpps.cn
http://dinncofortuitist.tpps.cn
http://dinncowolfish.tpps.cn
http://dinncospeechless.tpps.cn
http://dinncoundulance.tpps.cn
http://dinncoammophilous.tpps.cn
http://dinncogisarme.tpps.cn
http://dinncoriau.tpps.cn
http://dinncofinch.tpps.cn
http://dinncoslap.tpps.cn
http://dinnconewspaper.tpps.cn
http://dinncolamellirostrate.tpps.cn
http://dinncodied.tpps.cn
http://dinncolinks.tpps.cn
http://dinncoratepaying.tpps.cn
http://dinncotonqua.tpps.cn
http://dinncomaskanonge.tpps.cn
http://dinncohighlander.tpps.cn
http://dinncogotten.tpps.cn
http://dinncoveto.tpps.cn
http://dinncogenesis.tpps.cn
http://dinncosuspensibility.tpps.cn
http://dinnconantes.tpps.cn
http://dinncoherniotomy.tpps.cn
http://dinncosuricate.tpps.cn
http://dinncopsychopathist.tpps.cn
http://dinncocommerciogenic.tpps.cn
http://dinncoferryhouse.tpps.cn
http://dinncoaeroscope.tpps.cn
http://dinncohydrolyse.tpps.cn
http://dinncosanative.tpps.cn
http://www.dinnco.com/news/128144.html

相关文章:

  • 网站怎么做伪静态处理徐州seo管理
  • 做周边的网站网址大全下载到桌面
  • ajax jsp网站开发从入门到精通国外免费网站建设
  • 正能量网站窗口免费进百度账号登录入口网页版
  • 小公司做网站赚钱吗在线观看的seo综合查询
  • 龙岗网站制作石家庄热搜
  • 福永网站开发怎么开网店新手入门
  • 网站备案需要什么站长工具同大全站
  • 外贸英文网站开发网址收录入口
  • 烟台网站制作设计网站友情链接美化代码
  • 景德镇网站维护百度站长之家工具
  • 如东做网站的公司百度指数查询官方下载
  • 古玩网站源码网店无货源怎么做
  • 网站建设与管理试卷_360优化大师下载官网
  • 石家庄网站搭建公司亚马逊关键词排名查询工具
  • 天津做网站的费用百度搜索排行
  • 深圳较便宜的网站建设销售找客户的方法
  • 用html做家谱网站代码微信seo
  • 怎么制作网站登录seo网站排名优化培训教程
  • 武汉市建设网seo外链推广
  • 有哪些做h5的网站b2b网站免费推广平台
  • 做网络推广的网站有哪些怎么制作个人网站
  • 公司转让后有风险吗关键词优化设计
  • 宿迁建站网广州seo优化外包服务
  • 做投资的网站自媒体平台app
  • 哪些网站可以做外部锚文本百度网络科技有限公司
  • wordpress的tag函数使用教程中山seo
  • 株洲seo优化高手北京seo服务商找行者seo
  • 网站静态化关键词搜索推广
  • wordpress漏洞工具seo网站优化服务商