Skip to content

Commit

Permalink
Simplify Vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
robdekort committed Sep 26, 2023
1 parent a486de8 commit 5709e97
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
import laravel from 'laravel-vite-plugin'
import { defineConfig, loadEnv } from 'vite'
import { networkInterfaces } from 'os'
import VitePluginBrowserSync from 'vite-plugin-browser-sync'

/** @type {import('vite').UserConfig} */
export default defineConfig(({ mode }) => {
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const ip = Object.values(networkInterfaces()).flat().find((i) => i.family === 'IPv4' && !i.internal)?.address
const isSecuredSite = env.APP_URL.startsWith('https://')
const url = env.APP_URL
const host = url.replace(/^https?:\/\//, '')
const useBrowserSync = env.VITE_BROWSERSYNC && ip

if (useBrowserSync && isSecuredSite) {
console.log('\x1b[31m%s\x1b[0m', 'Sorry, we didn\'t manage to get BrowserSync working with secured sites.');
console.log('\x1b[31m%s\x1b[0m', 'If you can provide a solution, please enlighten us (https://github.com/studio1902/statamic-peak/pulls).');
process.exit(1)
}

return {
plugins: [
laravel({
refresh: true,
valetTls: isSecuredSite ? host : false,
input: [
'resources/css/site.css',
'resources/js/site.js',
]
}),
(() => {
return useBrowserSync ? VitePluginBrowserSync({
bs: {
proxy: url,
notify: false,
open: 'external',
},
}) : null;
})()
})
],
server: {
host: useBrowserSync ? ip : host,
open: useBrowserSync ? false : url,
open: env.APP_URL
}
}
});

0 comments on commit 5709e97

Please sign in to comment.