Skip to content

Commit e011972

Browse files
committed
feat: support vue-cli
1 parent 0799106 commit e011972

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module.exports = {
8080
```bash
8181
# macOS
8282
sudo -E npm run dev # your dev script
83+
# ^ `-E` is important
8384

8485
# windows
8586
# use powershell as administrator

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
}
114114
},
115115
"dependencies": {
116+
"esno": "^0.17.0",
116117
"got-cjs": "^12.5.4",
117118
"hostile": "^1.3.3",
118119
"http-proxy-agent": "^7.0.0",
@@ -131,7 +132,6 @@
131132
"bumpp": "^9.2.0",
132133
"chalk": "^5.3.0",
133134
"eslint": "^8.47.0",
134-
"esno": "^0.17.0",
135135
"fast-glob": "^3.3.1",
136136
"nodemon": "^3.0.1",
137137
"rimraf": "^5.0.1",

pnpm-lock.yaml

Lines changed: 32 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import { CaddyInstant } from './caddy'
88

99
let config: ResolvedConfig
1010

11+
let caddy: CaddyInstant
12+
1113
export const unpluginFactory: UnpluginFactory<Options> = options => ({
1214
name: 'unplugin-https-reverse-proxy',
15+
enforce: 'post',
1316
vite: {
1417
configResolved(_config) {
1518
config = _config
@@ -62,19 +65,33 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
6265
console.log('please provide target')
6366
return
6467
}
65-
const source = `${compiler.options.devServer?.host || '127.0.0.1'}:${compiler.options.devServer?.port || '8080'}`
66-
6768
try {
68-
const caddy = new CaddyInstant()
69+
// @ts-expect-error vuecli
70+
const devServer = compiler.options.devServer || process.VUE_CLI_SERVICE.projectOptions.devServer
71+
const source = `${devServer?.host || '127.0.0.1'}:${devServer?.port || '8080'}`
72+
73+
if (caddy)
74+
return
75+
76+
caddy = new CaddyInstant()
77+
6978
caddy.run(source, target).then((stop) => {
7079
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
71-
// eslint-disable-next-line no-console
72-
console.log(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}`)}`)
80+
81+
compiler.hooks.done.tap('unplugin-https-reverse-proxy', (stats) => {
82+
if (stats.hasErrors())
83+
return
84+
85+
// eslint-disable-next-line no-console
86+
console.log(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}`)}`)
87+
})
7388

7489
process.on('SIGINT', async () => {
7590
await stop()
7691
process.exit()
7792
})
93+
}).catch((e) => {
94+
throw e
7895
})
7996
}
8097
catch (e) {

0 commit comments

Comments
 (0)