npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-utools

v0.5.5-beta.0

Published

Utools for Vite

Downloads

57

Readme

vite-plugin-utools

Utools for Vite

  • 支持 preload.js 模块化
  • 支持 uTools api 模块化
  • 支持插件打包

用法

npm i vite-plugin-utools -D

vite.config.js 中添加配置

import utools from 'vite-plugin-utools';

export default {
	plugins: [
		utools({
			external: 'uTools',
			preload: {
				path: './src/preload.ts',
				watch: true,
				name: 'window.preload',
			},
			buildUpx: {
				pluginPath: './plugin.json',
				outDir: 'upx',
				outName: '[pluginName]_[version].upx',
			},
		}),
	],
};

preload.js 支持 ESM & 支持引入三方库

// preload.js

import { readFileSync } from 'fs';
import _fdir from 'fdir'

export const readConfig = () => readFileSync('./config.json');
export const fdir = _fdir

其他文件从 preload.js 中导入

// index.js

import { readConfig } from './preload';

console.log(readConfig());

上诉文件会转换为

// preload.js

window.preload = Object.create(null);

const { readFileSync } = require('fs')
const _fidr = require('fdir')

window.preload.readConfig =  () => readFileSync('./config.json');
window.preload.fdir = _fdir;
const readConfig = window.preload.readConfig

console.log(readConfig());

uTools api 支持 ESM

import { onPluginReady, getUser } from 'uTools';

onPluginReady(() => {
	console.log('Ready');
	console.log(getUser());
});

TypeScript 类型支持

可使用官方提供的 utools-api-types 类型文件

npm i -D utools-api-types
declare module 'uTools' {
	import Utools from 'utools-api-types';
	export = Utools;
}

Upx 打包

在插件的 plugin.json 文件添加额外配置

"name": "demo", // uTools 开发者工具中的项目 id
"version": "1.0.0",  
"pluginName": "demo",  
"description": "demo", 
"author": "yo3emite",  
"homepage": "https://github.com/13enbi",

可将 vite 构建后的产物打包成 uTools 的 upx 离线包

配置

external

扩展 window.utools 的模块名,默认为 utools-api-types

preload.path

preload.js 文件路径,默认为 ./src/preload

preload. name

preload.js 模块在 window 的挂载名,默认为 window.preload

preload.watch

preload.js 模块修改后重新构建,配合 uTools 开发者工具开启隐藏插件后完全退出使用

buildUpx.pluginPath

插件 plugin.json 文件路径

buildUpx.outDir

插件打包输出路径,默认为 upx

buildUpx.outName

插件输出文件名,默认为 [pluginName]_[version].upx