feat: add app fof iife
This commit is contained in:
parent
3b19cd8581
commit
9b3de5eba3
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/store",
|
"name": "@kevisual/store",
|
||||||
"version": "0.0.1-alpha.7",
|
"version": "0.0.1-alpha.8",
|
||||||
"main": "dist/store.js",
|
"main": "dist/store.js",
|
||||||
"module": "dist/store.js",
|
"module": "dist/store.js",
|
||||||
"types": "dist/store.d.ts",
|
"types": "dist/store.d.ts",
|
||||||
@ -69,6 +69,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@kevisual/router": "0.0.6-alpha-4",
|
||||||
|
"@rollup/plugin-terser": "^0.4.4",
|
||||||
"eventemitter3": "^5.0.1",
|
"eventemitter3": "^5.0.1",
|
||||||
"path-to-regexp": "^8.2.0"
|
"path-to-regexp": "^8.2.0"
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import typescript from '@rollup/plugin-typescript';
|
|||||||
import resolve from '@rollup/plugin-node-resolve';
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
import { dts } from 'rollup-plugin-dts';
|
import { dts } from 'rollup-plugin-dts';
|
||||||
|
import terser from '@rollup/plugin-terser';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {import('rollup').RollupOptions}
|
* @type {import('rollup').RollupOptions}
|
||||||
@ -77,4 +78,20 @@ export default [
|
|||||||
},
|
},
|
||||||
plugins: [dts()],
|
plugins: [dts()],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: 'src/app.ts',
|
||||||
|
output: {
|
||||||
|
file: 'dist/app.js',
|
||||||
|
format: 'iife',
|
||||||
|
},
|
||||||
|
plugins: [resolve({ browser: true }), commonjs(), typescript(), terser()],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'src/app.ts',
|
||||||
|
output: {
|
||||||
|
file: 'dist/app.d.ts',
|
||||||
|
format: 'es',
|
||||||
|
},
|
||||||
|
plugins: [dts()],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
12
src/app.ts
Normal file
12
src/app.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// 当前的功能,把所有的模块注入到windows对象当中
|
||||||
|
import { useConfigKey, useContextKey } from './web-env.ts';
|
||||||
|
import { QueryRouterServer } from '@kevisual/router/browser';
|
||||||
|
|
||||||
|
// bind to window, 必须要的获取全局的环境变量
|
||||||
|
window.useConfigKey = useConfigKey;
|
||||||
|
window.useContextKey = useContextKey;
|
||||||
|
window.QueryRouterServer = QueryRouterServer;
|
||||||
|
|
||||||
|
// bind to window, 获取路由对象
|
||||||
|
useContextKey('app', () => new QueryRouterServer());
|
||||||
|
|
@ -4,6 +4,7 @@ type GlobalEnv = {
|
|||||||
name?: string;
|
name?: string;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
// 从window对象中获取全局的环境变量,如果没有则初始化一个
|
||||||
export const useEnv = (initEnv?: GlobalEnv, initKey = 'config') => {
|
export const useEnv = (initEnv?: GlobalEnv, initKey = 'config') => {
|
||||||
const env: GlobalEnv = (window as any)[initKey];
|
const env: GlobalEnv = (window as any)[initKey];
|
||||||
const _env = env || initEnv;
|
const _env = env || initEnv;
|
||||||
@ -17,6 +18,7 @@ export const useEnv = (initEnv?: GlobalEnv, initKey = 'config') => {
|
|||||||
return window[initKey] as GlobalEnv;
|
return window[initKey] as GlobalEnv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 从全局环境变量中获取指定的key值,如果没有则初始化一个, key不存在,返回Env对象
|
||||||
export const useEnvKey = <T = any>(key: string, init?: () => T | null, initKey = 'config'): T => {
|
export const useEnvKey = <T = any>(key: string, init?: () => T | null, initKey = 'config'): T => {
|
||||||
const _env = useEnv({}, initKey);
|
const _env = useEnv({}, initKey);
|
||||||
if (key && _env[key]) {
|
if (key && _env[key]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user