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-uni-platform-loader

v1.0.6

Published

一个基于vite的,在uniapp中使用的插件。会根据当前编译的平台自动加载对应的文件。

Downloads

503

Readme

vite-plugin-uni-platform-loader

一个基于vite的,在uniapp中使用的插件。会根据当前编译的平台(默认是h5)自动加载对应的文件。

例如:h5平台默认加载index.vue;微信小程序平台会加载index.mp-weixin.vue,若没有则加载index.vue

安装

.npmrc中指定镜像

vite-plugin-uni-platform-loader:registry=https://registry.npmjs.org/

安装插件

npm i -D vite-plugin-uni-platform-loader

使用

vite.config.ts中使用

import UniPlatformLoader from 'vite-plugin-uni-platform-loader';
import path from 'path';

export default defineConfig({
  plugins: [
    UniPlatformLoader({
      platform: process.env.UNI_PLATFORM,
      rootDir: path.resolve(__dirname, 'src'),
    }),
  ],
});

插件选项

| 参数名 | 类型 | 默认值 | 说明 | | -------- | ------ | ------ | ------ | | rootDir | string | src | 根目录 | | platform | string | h5 | 平台 |

实现原理

vite-plugin-uni-platform-loader插件会监听rootDir目录下的文件变化,当文件发生变化时,会更新默认文件中的注释,重新触发vite的构建。

image-20241030144938478

vite构建时在transform钩子中寻找当前文件与平台匹配的文件(例如:小程序平台会根据index.vue寻找index.mp-weixin.vue文件),并返回文件内容。

需要注意的是:h5平台会忽略index.h5.vue文件,因为index.vue默认为h5平台的文件

更新日志

| 版本 | 更新内容 | | ----- | ---------------------------------- | | 1.0.6 | 更新README | | 1.0.5 | 修复默认rootDir路径错误问题 | | 1.0.4 | 更新README | | 1.0.3 | 修复微信小程序平台文件重新加载问题 |