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

@xyh19/vite-plugin-electron

v1.8.0

Published

Vite plugin base electron-builder and rollup

Downloads

5

Readme

一个使用electron-builder构建electron应用程序的vite插件

特性

  1. 默认支持模块热替换(方便开发)
  2. 默认支持打包静态资源(图片,视频等)
  3. 支持.node模块打包
  4. 渲染进程支持node模块

安装

npm i --save-dev @xyh19/vite-plugin-electron
# or
yarn add -D @xyh19/vite-plugin-electron

快速使用

  1. vite.config.js 文件中注册插件:
import { defineConfig } from 'vite'
import electron from '@xyh19/vite-plugin-electron'

export default defineConfig({
  plugins: [
    electron({
      input: {
        appEntry: 'src/main/app.ts', //app入口
        entries: ['src/main/preload.ts'], //preload
      },
    }),
  ]
})
  1. package.json 文件中设置scripts
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "serve": "electron dist/index.js",
  }
  1. 启动开发服务器
npm run dev
# or
yarn dev
  1. 构建项目
npm run build
# or
yarn build

注意

  1. 如果需要启动 typescript 装饰器功能,请设置 esbuild = false

选项声明

import { Plugin } from 'vite';
import * as electron_builder from 'electron-builder';
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
import { UserOptions as UserOptions$1 } from '@xyh19/rollup-plugin-assets';
import rollup from 'rollup';
import { Options } from 'rollup-plugin-esbuild';
import { CustomTransformerFactories } from '@rollup/plugin-typescript';

interface UserOptions {
    input?: {
        /**
         * app入口
         * @default (__dirname+'../lib/app-entry.js')
         */
        appEntry?: string;
        /**
         * 其他入口(preload等)
         */
        entries?: string | string[];
        srcRoot?: string;
    };
    output?: {
        /**
         * 输出目录
         * @default 'dist'
         */
        dir?: string;
        /**
         * renderer 输出目录,相对于 output.dir
         * @default 'renderer'
         */
        rendererDir?: string;
        /**
         * Whether to Object.freeze() namespace import objects (i.e. import * as namespaceImportObject from...) that are accessed dynamically.
         * @default true
         */
        freeze?: boolean;
        /**
         * 要在捆绑包中添加/附加的字符串。您还可以提供一个函数,该函数返回解析为字符串的承诺,以异步生成它(注意:横幅和页脚选项不会破坏sourcemaps)。
         */
        banner?: string | (() => string | Promise<string>);
        footer?: string | (() => string | Promise<string>);
        intro?: string | (() => string | Promise<string>);
        outro?: string | (() => string | Promise<string>);
        /**
         * 允许创建自定义共享公共块。当使用对象形式时,每个属性代表一个包含列出的模块及其所有依赖项的块,如果它们是模块图的一部分,除非它们已经在另一个手动块中。块的名称将由属性键确定。
         * @example ```
         *  manualChunks: {
         *    lodash: ['lodash']
         *  }
         * ```
         */
        manualChunks?: rollup.ManualChunksOption;
        /** Maps external module IDs to paths. External ids are ids that cannot be resolved or ids explicitly provided by the external option. Paths supplied by output.paths will be used in the generated bundle instead of the module ID, allowing you to, for example, load dependencies from a CDN */
        paths?: rollup.OptionsPaths;
        sourcemap?: boolean | 'inline' | 'hidden';
        sourcemapExcludeSources?: boolean;
        sourcemapFile?: string;
        sourcemapPathTransform?: rollup.SourcemapPathTransformOption;
        validate?: boolean;
    };
    root?: string;
    /**
     * rollup watch
     */
    watch?: rollup.WatcherOptions | false;
    /**
     * 是否强制重启
     * @default false
     */
    forceRestart?: boolean | (() => boolean | Promise<boolean>);
    /**
     * ts配置文件
     * @default (process.cwd()+'tsconfig.json')
     */
    tsconfig?: false | string;
    tsTransformers?: CustomTransformerFactories;
    /**
     * 定义全局常量替换方式。其中每项在开发环境下会被定义在全局,而在构建时被静态替换。
     * @see https://cn.vitejs.dev/config/#define
     */
    define?: Record<string, string>;
    build?: electron_builder.Configuration;
    /**
     * rollup插件
     */
    plugins?: ((rollup.Plugin & {
        enforce?: 'pre' | 'post';
    }) | null | false | undefined)[];
    /**
     * 外部模块
     */
    external?: (string | RegExp)[];
    commonjsOptions?: RollupCommonJSOptions;
    esbuild?: false | Options;
    esbuildOptions?: Options;
    treeshake?: rollup.TreeshakingOptions;
    /**
     * @deprecated
     * 指定额外的 picomatch 模式 作为静态资源处理。
     */
    assetsInclude?: string | RegExp | (string | RegExp)[];
    assetsOptions?: UserOptions$1;
}

declare function electronBuilder(options?: UserOptions): Plugin;

export { UserOptions, electronBuilder as default };

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Give a ⭐️ if this project helped you!