0.0.2 • Published 3 years ago
vite-plugin-web-config v0.0.2
vite-plugin-web-config
- Configure vite server proxy in development mode.
- In build mode, it will generate
web.config(IIS server config) file with rewrite rules in thedistdirectory.
Install
# npm
npm i vite-plugin-web-config -D
# yarn
yarn add vite-plugin-web-config -D
# pnpm
pnpm add vite-plugin-web-config -DUsage
Add plugin to vite.config.ts:
import WebConfig from 'vite-plugin-web-config'
export default {
plugins: [
WebConfig({
proxy: [['/api', 'http://localhost:3000']],
output: 'web.config',
}),
],
}Options
| Name | Type | Default | Description |
|---|---|---|---|
| proxy | [string, string][] | [] | Proxy list config |
| output | string \| false | web.config | Output file name. |
Except for the above options, you can also configure VITE_PROXY in .env.* file:
VITE_PROXY = [["/api","http://localhost:3000"]]Must be a valid JSON string.
If provideproxyoption,.env.*config will be ignored.
Whenoutputisfalse, it will not generateweb.configfile.
In development mode, vite will automatically configure the proxy according to the configuration in the .env.* file or options.proxy.
// vite.config.ts
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
},
},
},
})After running vite build, the web.config file will be generated in the dist directory.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="api_rule" stopProcessing="true">
<match url="api/(.*)"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="api/(.*)"/>
</conditions>
<action type="Rewrite" url="http://localhost:3000/{R:1}" logRewrittenUrl="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>Example
License
0.0.2
3 years ago
0.0.1
3 years ago
0.0.1-beta.2
3 years ago
0.0.1-beta.1
3 years ago
0.0.1-beta.0
3 years ago