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-version-env

v1.0.4

Published

Downloads

100

Readme

vite打包静态资源版本控制

不同环境的全局参数配置。

增强代理配置功能,可实现不同接口走不同的代理,也可过滤指定接口。

安装

npm i vite-plugin-version-env -S

配置

环境参数配置

build/config
	development.ts
	production.ts
	test.ts
	
//配置信息 development.ts
export default {
  //    全局配置项,打包后会存入 app.config.js文件中。
  GLOBAL_CONFIG: {
    web_tilte: '开发环境',
    cache_store: ['oauth', 'global'],
    api_base: 'http://fyeb.cnsaas.com/support-gateway/',
    api_idaas: '/idaas/',
    api_file: '/file-service/',
    api_security: '/fy-security/',
    api_gis: '/',
  },
  DEV: {
    port: 8080,
    proxy: true,
    proxy_list: [
      {
        name: '/_api/',
        include: '^/gisLayerGroup',
        target: 'http://172.16.105.9:30006',
      },
    ],
  },
} as VersionEnvSpace.EnvConfig;


配置项类型 :VersionEnvSpace

declare namespace VersionEnvSpace {
  interface GlobalConfig {
    api_base: string;
    DEV?: DevConfig;
    [x: string]: any;
  }
  interface DevConfig {
    port?: number;
    proxy?: boolean;
    proxy_list?: {
      name: string;
      include?: string;
      exclude?: string;
      target: string;
    }[];
    [x: string]: any;
  }
  interface EnvConfig {
    GLOBAL_CONFIG: GlobalConfig;
    DEV?: DevConfig;
  }
}
declare const GLOBAL_CONFIG: VersionEnvSpace.GlobalConfig;

扩展配置项类型

global.d.ts

namespace VersionEnvSpace {
    interface GlobalConfig {
      web_tilte?: string;
      cache_store: string[];
      api_base: string;
      api_idaas: string;
      api_file: string;
      api_security: string;
      api_gis: string;
    }
  }

构建配置

vite.config.ts


import { ServerPlugin, VersionPlugin } from 'vite-plugin-version-env';

export default defineConfig(async ({ mode, command }: ConfigEnv): Promise<UserConfig> => {
  const CustomEnv = (await import(`./build/config/${mode}.ts`)).default as VersionEnvSpace.EnvConfig;
   return {
    plugins: [ VersionPlugin({ CustomEnv, command, '__GLOBAL_CONFIG__', 'app.config.js' }),],
    server: {  
      cors: true,
      open: true,
      host: '0.0.0.0',
      ...ServerPlugin(CustomEnv)
      }
   }

VersionPluginType

({ CustomEnv, command, cleanDir, GLOBAL_CONFIG_FILE_NAME, GLOBAL_CONFIG_KEY, GLOBAL_CONFIG_NAME, }: {
    CustomEnv: VersionEnvSpace.EnvConfig;
    command: 'build' | 'serve';
    cleanDir?: boolean;
    GLOBAL_CONFIG_FILE_NAME?: string;
    GLOBAL_CONFIG_KEY?: string;
    GLOBAL_CONFIG_NAME?: string;
}) 

| 属性 | 类型 | 描述 | 默认值 | |---------------------------|---------|-------------------------------|-----------------| | CustomEnv | Object | 配置对象 | - | | command | 'build' |'serve' | | - | | cleanDir | Boolean | 是否清空输出目录 | true | | GLOBAL_CONFIG_FILE_NAME | String | 存放全局配置的文件名 | app.config.js | | GLOBAL_CONFIG_KEY | String | 挂载到 window 对象上的属性名 | \__GLOBAL_CONFIG__ | | GLOBAL_CONFIG_NAME | String | 代码可用的全局对象名 | GLOBAL_CONFIG |

Axios配置

import { ConfigBaseUrl } from 'vite-plugin-version-env/ConfigBaseUrl';
http.interceptors.request.use(async (config) => {
  ConfigBaseUrl(config);
   return config;
  }

ConfigBaseUrl

  • 开发环境下,axios中无需配置baseUrl,自动依据代理配置,设置成代理字符。没有代理时使用GlobalConfig.api_base

  • 生产环境,使用GlobalConfig.api_base

(AxiosConfig: InternalAxiosRequestConfig<any>, GlobalConfig?: VersionEnvSpace.GlobalConfig) => void

若GLOBAL_CONFIG_NAME没有自定义,则可以不用传,若自定义则必须传入自定义的

并且需要在类型文件中声明其类型

global.d.ts

declare const CUSTON_GLOBAL_CONFIG: VersionEnvSpace.GlobalConfig;

TS 配置

"types": [ 

​      "vite-plugin-version-env/client", 

​    ],