GithubHelp home page GithubHelp logo

vite-plugin-utools-helper's Introduction

vite-plugin-utools-helper

使用 Vite 开发和编译 utools 插件

  • 支持 preload 编译
  • 支持 打包 upx

配置相关可参考此插件: utools-plugin-tinypng

如何使用

1. 安装 vite-plugin-utools-helper

npm i vite-plugin-utools-helper -D

2. 修改 vite.config.ts

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createPreloadPlugin, createUpxPlugin } from 'vite-plugin-utools-helper';
import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import';

export default defineConfig({
  base: './',
  server: {
    port: 3100
  },
  plugins: [
    vue(),
    createStyleImportPlugin({
      resolves: [ElementPlusResolve()]
    }),
    /**
     * preload 已禁用压缩,不建议引用较大第三方库,否则有可能审核不通过
     */
    createPreloadPlugin({
      // name: 'window.preload',       // 修改 preload.ts 导出到全局变量的名称
      // path: 'src/preload/index.ts', // 修改 preload.ts 的路径
    }),
    /**
     * 核心逻辑参考自: https://github.com/13enBi/vite-plugin-utools/blob/main/src/buildUpx.ts
     */
    createUpxPlugin({
      // outDir: 'upx',
      outFileName: 'tinypng-[version].upx'
    })
  ]
});

3. 修改 ./public/plugin.json

若使用 createUpxPlugin 功能,以下字段为必选项,缺少将影响 utoolsupx 文件的识别

name, pluginName, description, author, homepage, version, logo, features

{
  // 对 plugin.json 增加类型校验和提示
  "$schema": "../node_modules/vite-plugin-utools-helper/dist/schema.json",
  "name": "abcdefg", // uTools 开发者工具中的项目 id
  "pluginName": "插件名称",
  "description": "插件描述",
  "author": "https://github.com/csj8520", // 作者主页地址
  "homepage": "https://github.com/csj8520/utools-plugin-tinypng", // 此插件主页地址
  "version": "0.0.1",

  "logo": "logo.png",
  "main": "index.html", // 固定路径
  "preload": "preload.js", // 固定路径
  "development": {
    "main": "http://localhost:3100", // 端口和 vite.config.ts 保持一致
    "preload": "preload.js" // 固定路径
  },
  "features": [] // ...
}

4. 修改 ./src/types.d.ts

增加如下声明

declare interface Window {
  preload?: typeof import('./preload/index');
}

5. 执行 npm run start | npm run build

6. 修改 utools 开发者工具配置

重新选择 plugin.json 路径为 ./dist/plugin.json

添加 utools api 的类型定义

npm i utools-api-types -D

修改 tsconfig.json

添加如下内容

{
  "compilerOptions": {
    "types": ["utools-api-types"]
  }
}

vite-plugin-utools-helper's People

Contributors

csj8520 avatar iamxiyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lgf-136

vite-plugin-utools-helper's Issues

什么时候支持upxs

谢谢作者提供这么好的插件,请问什么时候可以支持5.0版本的upxs呀

createPreloadPlugin 生成的文件会错误的把函数传参进行导出

复现步骤:

克隆作者自己的项目 https://github.com/csj8520/utools-plugin-tinypng/tree/master

安装依赖

pnpm install

构建项目

pnpm start

查看 dist/preload.js 会发现在最后一行额外多了data 的导出,这个 data 其实是 writeFile 方法的第二个参数。

如果修改 src/preload/index.ts ,在任意方法上添加多个传参,会发现所有包含多个的参数都会被错误的收集、导出。

假设在 src/preload/index.ts 添加

export function testA(a1: any, a2: any, a3: any) {
  return { a1, a2, a3 }
}

查看 dist/preload.js ,发现最后不止有 testA、还有 a2、a3,这是不符合预期的。

修复建议:

mlly 某个版本行为发生了变化,可以考虑对 declaration 只收集 name

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.