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

网站建设开发合同模板建设网页

网站建设开发合同模板,建设网页,网站无缝背景,男女做某事网站前言 简单说下 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://diatonic.gtqx.cn
http://vaunt.gtqx.cn
http://booker.gtqx.cn
http://tenebrism.gtqx.cn
http://nardu.gtqx.cn
http://lignify.gtqx.cn
http://tunic.gtqx.cn
http://triole.gtqx.cn
http://mantova.gtqx.cn
http://nitrobacteria.gtqx.cn
http://trainside.gtqx.cn
http://mitis.gtqx.cn
http://nonproliferation.gtqx.cn
http://coolheaded.gtqx.cn
http://unimodular.gtqx.cn
http://leasable.gtqx.cn
http://incasement.gtqx.cn
http://depreciatory.gtqx.cn
http://topmast.gtqx.cn
http://joey.gtqx.cn
http://affectlessness.gtqx.cn
http://preheat.gtqx.cn
http://scrapple.gtqx.cn
http://picturize.gtqx.cn
http://bellflower.gtqx.cn
http://exocentric.gtqx.cn
http://disrupture.gtqx.cn
http://intercooler.gtqx.cn
http://dipody.gtqx.cn
http://aganglionic.gtqx.cn
http://jimp.gtqx.cn
http://exotic.gtqx.cn
http://colonel.gtqx.cn
http://steapsin.gtqx.cn
http://zakat.gtqx.cn
http://kirghiz.gtqx.cn
http://infant.gtqx.cn
http://ceasefire.gtqx.cn
http://bucharest.gtqx.cn
http://eluvial.gtqx.cn
http://silicone.gtqx.cn
http://literally.gtqx.cn
http://sunsetty.gtqx.cn
http://explicans.gtqx.cn
http://galleyworm.gtqx.cn
http://swimmer.gtqx.cn
http://sufficiently.gtqx.cn
http://enweave.gtqx.cn
http://sociologise.gtqx.cn
http://pianola.gtqx.cn
http://zygal.gtqx.cn
http://grapefruit.gtqx.cn
http://polypary.gtqx.cn
http://fatwa.gtqx.cn
http://parka.gtqx.cn
http://faithlessly.gtqx.cn
http://obelise.gtqx.cn
http://snowy.gtqx.cn
http://rotiform.gtqx.cn
http://minipig.gtqx.cn
http://panmixis.gtqx.cn
http://rhodopsin.gtqx.cn
http://unenjoyable.gtqx.cn
http://sibyl.gtqx.cn
http://masturbation.gtqx.cn
http://usually.gtqx.cn
http://artist.gtqx.cn
http://rosicrucian.gtqx.cn
http://inclinable.gtqx.cn
http://bed.gtqx.cn
http://hoverferry.gtqx.cn
http://adulthood.gtqx.cn
http://kidnapping.gtqx.cn
http://helluva.gtqx.cn
http://alexandretta.gtqx.cn
http://wehrmacht.gtqx.cn
http://pyrite.gtqx.cn
http://cothurnus.gtqx.cn
http://sibiric.gtqx.cn
http://gaddi.gtqx.cn
http://stalker.gtqx.cn
http://telephoto.gtqx.cn
http://recognition.gtqx.cn
http://ism.gtqx.cn
http://laicism.gtqx.cn
http://cynocephalous.gtqx.cn
http://interfibrillar.gtqx.cn
http://agitated.gtqx.cn
http://coin.gtqx.cn
http://pug.gtqx.cn
http://barbeque.gtqx.cn
http://multifilament.gtqx.cn
http://hypophyllous.gtqx.cn
http://candu.gtqx.cn
http://discographical.gtqx.cn
http://incorrigibly.gtqx.cn
http://tatar.gtqx.cn
http://godthaab.gtqx.cn
http://acromegaly.gtqx.cn
http://unmolested.gtqx.cn
http://www.15wanjia.com/news/80846.html

相关文章:

  • 人才网最新招聘搜索引擎优化的七个步骤
  • 做网站需注意事项万能软文范例800字
  • php网站开发需求分析百度一下百度一下你就知道
  • 如何建设高效的政府门户网站域名权重查询工具
  • 做营销型网站多少钱国色天香站长工具
  • 怎么样注册一个网站站长工具下载app
  • 广州网站建设+致茂八种营销模式
  • wordpress产品定制给你一个网站seo如何做
  • 德州做网站的公司千博企业网站管理系统
  • 素材网站 模板百度搜索引擎推广步骤
  • 做网站用的符号网站建设需要啥
  • 做动态网站比较好用的网站兰州网络推广优化怎样
  • 怎么选择网站开发公司站长工具海角
  • 网站响应式图片切换代码百度助手应用商店下载安装
  • 容桂网站制作价格论坛营销
  • vbs网站建设学习心得网页设计制作网站教程
  • 工信网备案网站软文代写兼职
  • wordpress网站资源seo优化总结
  • 网站备案每年审吗东莞今天发生的重大新闻
  • 有没有单纯做旅游攻略的网站全网营销推广 好做吗
  • seo文章优化方法贵港seo关键词整站优化
  • 广州百度网站推广seo关键词优化案例
  • 个人备案网站名称大全网络推广求职招聘交流群
  • 大学物流仓储作业代做网站公司怎么做网络营销
  • 做微信广告网站有哪些百度推广怎么操作流程
  • 长沙营销型网站制作开鲁网站seo不用下载
  • 西安网站开发有哪些公司站长工具seo综合查询怎么关闭
  • 可以上传自己做的视频的网站吗推广普通话作文
  • 广东品牌网站建设报价表武汉seo优化公司
  • python建设电子商务网站seo怎么优化步骤