-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f64b655
commit 3b24f9b
Showing
11 changed files
with
714 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
import { globalConst } from 'vite-plugin-global-const' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [vue()], | ||
plugins: [ | ||
globalConst({ | ||
Text: 'Hello World!', | ||
MAIN: true | ||
}), | ||
|
||
vue(), | ||
], | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function globalConst(config) { | ||
return { | ||
name: 'vite-plugin-global-const', | ||
config() { | ||
console.log(config); | ||
const define = {}; | ||
for (const key in config) { | ||
define[`import.meta.env.${key}`] = JSON.stringify(config[key]); | ||
} | ||
return { | ||
define, | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import shell from 'shelljs'; | ||
|
||
//执行一遍npm run build | ||
shell.exec('yarn run build'); | ||
|
||
//删除demo/node_modules的所有文件 | ||
shell.rm('-rf', 'demo/node_modules'); | ||
|
||
//进入demo目录 | ||
shell.cd('demo'); | ||
|
||
//安装demo/node_modules | ||
shell.exec('yarn'); | ||
|
||
//启动demo | ||
shell.exec('yarn run dev'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
//使用这个函数挂载到vite上,可以在任何地方使用 | ||
export function globalConst(){ | ||
import { Plugin } from 'vite'; | ||
|
||
interface Config { | ||
[key: string]: any; | ||
} | ||
|
||
export function globalConst(config: Config): Plugin { | ||
return { | ||
name:'vite-plugin-global-const', | ||
//挂载后接收用户传入的参数 | ||
config(config){ | ||
return { | ||
define:{ | ||
//这里的key就是用户传入的key,value就是用户传入的value | ||
'process.env':{ | ||
...config | ||
} | ||
} | ||
name: 'vite-plugin-global-const', | ||
config() { | ||
console.log(config); | ||
const define = {}; | ||
for (const key in config) { | ||
define[`import.meta.env.${key}`] = JSON.stringify(config[key]); | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
define, | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Plugin } from 'vite'; | ||
interface Config { | ||
[key: string]: any; | ||
} | ||
export declare function globalConst(config: Config): Plugin; | ||
export {}; |
Oops, something went wrong.