Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[vite-plugin-ruby]: https://github.com/ElMassimo/vite_ruby/tree/main/vite-plugin-ruby
[Vite config file]: /config/#configuring-vite-⚡
[runtime env var]: https://github.com/ElMassimo/vite_ruby/discussions/159#discussioncomment-1841817
[emptyOutDir]: https://vitejs.dev/config/#build-emptyoutdir

# Configuring Vite Ruby

Expand Down Expand Up @@ -101,7 +102,7 @@ const adminAssetsPath = process.env.ADMINISTRATOR_ASSETS_PATH

## Source Maps 🗺

The only notable difference with Vite.js config defaults, is that [source maps]
One notable difference with Vite.js config defaults, is that [source maps]
are enabled in production to be in [alignment with Rails defaults].

You may skip source map generation by explicitly configuring <kbd>[sourcemap][source maps]</kbd>:
Expand All @@ -112,6 +113,19 @@ export default defineConfig({
build: { sourcemap: false },
```

## Emptying the Dist Dir 📦

Another notable difference with Vite.js config defaults, is that <kbd>[emptyOutDir]</kbd>
is disabled in production to provide better support for deployments that don't use a CDN,
to preserve assets from previous builds upon deployment in order to avoid downtime.

You may override this behavior manually:

```js
// vite.config.ts
export default defineConfig({
build: { emptyOutDir: true },
```

## Development Options

Expand Down
6 changes: 4 additions & 2 deletions vite-plugin-ruby/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ function config (userConfig: UserConfig, env: ConfigEnv): UserConfig {
const fs = { allow: [projectRoot], strict: true }
const hmr = userConfig.server?.hmr ?? { host, port }
const server = { host, https, port, strictPort: true, fs, hmr }

const isProduction = config.mode === 'production'

const build = {
emptyOutDir: true,
sourcemap: config.mode === 'production',
emptyOutDir: userConfig.build?.emptyOutDir ?? !isProduction,
sourcemap: isProduction,
...userConfig.build,
assetsDir,
manifest: true,
Expand Down