Skip to content

Commit

Permalink
暂存更改
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed Nov 11, 2023
1 parent 5e07a71 commit 74a69ac
Show file tree
Hide file tree
Showing 10 changed files with 1,264 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ out

# Nuxt.js build / generate output
.nuxt
dist
# dist

# Gatsby files
.cache/
Expand Down
15 changes: 15 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
// dts: {
// compilerOptions:{}
// }
},
})
23 changes: 23 additions & 0 deletions dist/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

function globalConst(config) {
return {
name: "vite-plugin-global-const",
config() {
const define = defineConstCore(config);
return {
define
};
}
};
}
function defineConstCore(config) {
const define = {};
for (const key in config) {
define[`import.meta.env.${key}`] = JSON.stringify(config[key]);
}
return define;
}

exports.defineConstCore = defineConstCore;
exports.globalConst = globalConst;
20 changes: 20 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function globalConst(config) {
return {
name: "vite-plugin-global-const",
config() {
const define = defineConstCore(config);
return {
define
};
}
};
}
function defineConstCore(config) {
const define = {};
for (const key in config) {
define[`import.meta.env.${key}`] = JSON.stringify(config[key]);
}
return define;
}

export { defineConstCore, globalConst };
18 changes: 0 additions & 18 deletions esm/index.js

This file was deleted.

24 changes: 16 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"name": "vite-plugin-global-const",
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"description": "Define constants for your project to facilitate reuse of your code across multiple products",
"main": "/esm/index.js",
"module": "/esm/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "types",
"repository": "https://github.com/censujiang/vite-plugin-global-const.git",
"homepage": "https://github.com/censujiang/vite-plugin-global-const",
"bugs": {
Expand All @@ -26,16 +34,16 @@
"/esm",
"/types"
],
"types": "types",
"scripts": {
"build": "tsc",
"build": "tsc && unbuild",
"demo:reload": "node ./scripts/demo-reload.js",
"release": "node ./scripts/release.js"
},
"devDependencies": {
"@types/node": "^20.2.3",
"@types/node": "^20.9.0",
"shelljs": "^0.8.5",
"typescript": "^5.0.4",
"vite": "^4.3.8"
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vite": "^4.5.0"
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Plugin } from 'vite';
import { Plugin as VitePlugin } from 'vite';

interface Config {
[key: string]: any;
}

export function globalConst(config: Config): Plugin {
export function globalConst(config: Config): VitePlugin {
return {
name: 'vite-plugin-global-const',
config() {
Expand Down
20 changes: 13 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"paths": {
"vite":["node_modules/vite/dist/index.esm.js"]
},
"paths": {
"vite": [
"node_modules/vite"
]
},
"baseUrl": "./",
"noImplicitAny": false,
"rootDir": "./src",
"outDir": "./esm",
"strict":false,
"noEmitOnError":false,
"outDir": "./esm",
"strict": false,
"noEmitOnError": false,
"declaration": true,
"declarationDir": "./types",
"types": [
"vite",
]
},
"include": [
"src//*.ts"
"src//*.ts",
"node_modules/vite/**/*.d.ts"
],
"exclude": [
"node_modules",
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from 'vite';
import { Plugin as VitePlugin } from 'vite';
interface Config {
[key: string]: any;
}
export declare function globalConst(config: Config): Plugin;
export declare function globalConst(config: Config): VitePlugin;
export declare function defineConstCore(config: Config): {};
export {};
Loading

0 comments on commit 74a69ac

Please sign in to comment.