Skip to content

Commit 89e6631

Browse files
committed
Add support for running inside a Sail container
1 parent b228d75 commit 89e6631

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export default function laravel(config?: string|string[]|Partial<PluginConfig>):
8181
},
8282
server: {
8383
origin: '__laravel_vite_placeholder__',
84+
...(process.env.LARAVEL_SAIL ? {
85+
host: '0.0.0.0',
86+
port: env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173,
87+
strictPort: true,
88+
} : undefined)
8489
},
8590
resolve: {
8691
alias: Array.isArray(userConfig.resolve?.alias)

tests/index.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ describe('laravel-vite-plugin', () => {
1919

2020
const serveConfig = plugin.config({}, { command: 'serve', mode: 'development' })
2121
expect(serveConfig.base).toBe('')
22+
expect(buildConfig.server.host).toBeUndefined()
23+
expect(buildConfig.server.port).toBeUndefined()
24+
expect(buildConfig.server.strictPort).toBeUndefined()
2225

2326
const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' })
2427
expect(ssrConfig.base).toBe('/build/')
@@ -188,4 +191,30 @@ describe('laravel-vite-plugin', () => {
188191

189192
expect(config.resolve.alias).toContainEqual({ find: 'ziggy', replacement: 'vendor/tightenco/ziggy/dist/index.es.js' })
190193
})
194+
195+
it('configures the Vite server when inside a Sail container', () => {
196+
process.env.LARAVEL_SAIL = '1'
197+
const plugin = laravel()
198+
199+
const config = plugin.config({}, { command: 'serve', mode: 'development' })
200+
expect(config.server.host).toBe('0.0.0.0')
201+
expect(config.server.port).toBe(5173)
202+
expect(config.server.strictPort).toBe(true)
203+
204+
delete process.env.LARAVEL_SAIL
205+
})
206+
207+
it('allows the Vite port to be configured when inside a Sail container', () => {
208+
process.env.LARAVEL_SAIL = '1'
209+
process.env.VITE_PORT = '1234'
210+
const plugin = laravel()
211+
212+
const config = plugin.config({}, { command: 'serve', mode: 'development' })
213+
expect(config.server.host).toBe('0.0.0.0')
214+
expect(config.server.port).toBe(1234)
215+
expect(config.server.strictPort).toBe(true)
216+
217+
delete process.env.LARAVEL_SAIL
218+
delete process.env.VITE_PORT
219+
})
191220
})

0 commit comments

Comments
 (0)