Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Introduce clean-orphaned-assets binary #251

Merged
merged 3 commits into from
Dec 14, 2023
Merged

[1.x] Introduce clean-orphaned-assets binary #251

merged 3 commits into from
Dec 14, 2023

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Oct 7, 2023

When deploying a site and building your assets during a deploy, if you have enough traffic, you can run into issues while building vite assets.

Vite will remove the manifest.json and all the existing assets in public/build/assets/* before it writes the new manifest and build assets.

This means for a brief time there is no manifest and also in-flight responses will reference assets that no longer exist on the server.

To resolve this you can build your assets and tell Vite not to clean the build directory:

npx vite build --emptyOutDir=false

Vite will now write over the manifest and will not remove the existing assets.

This is great, and generally good practice, but it introduces another problem: nothing is cleaning up the old assets. They will continue to grow and overtime these will build up to be a decent size.

This is where the new command comes in. It will read the current manifest and clean out any old build assets that are no longer referenced in the current manifest.

When running this command it is recommend you give a little time after building the new assets before running the command. You need to consider how long a response referencing old assets might take to return to the user and for them to then request the old assets.

npx vite build --emptyOutDir=false

# wait n seconds before cleaning out the old assets
sleep 3

npx clean-orphaned-assets

General Usage

Clean orphaned assets for non-SSR builds using conventional paths for the manifest and assets.

npx clean-orphaned-assets

**Of course I would love this to not be so verbose, but it needs to not conflict with other scripts that may have been configured.

Clean orphaned assets for SSR builds using conventional paths for the manifest and assets.

npx clean-orphaned-assets --ssr

Flags & Options

--ssr: Clean SSR assets.
--quiet: No output written.
--dry-run: Does not actually remove the files from the directory.
--manifest={path}: Specify a custom path to the manifest file.
--assets={path}: Specify a custom path to the assets directory.

Notes

  • I just let the "missing file" errors fall through from Node to keep things simple.

@timacdonald timacdonald changed the title [0.8.x] Introduce clean script [0.8.x] Introduce purge-orphaned-assets script Oct 8, 2023
@timacdonald timacdonald changed the title [0.8.x] Introduce purge-orphaned-assets script [0.8.x] Introduce purge-orphaned-assets binary Oct 8, 2023
package.json Outdated Show resolved Hide resolved
@timacdonald timacdonald marked this pull request as ready for review October 8, 2023 01:44
@timacdonald timacdonald marked this pull request as draft October 8, 2023 01:48
@timacdonald timacdonald marked this pull request as ready for review October 9, 2023 02:39
@timacdonald
Copy link
Member Author

See: laravel/framework#48964

@timacdonald timacdonald marked this pull request as draft December 10, 2023 23:26
@timacdonald timacdonald self-assigned this Dec 13, 2023
@timacdonald timacdonald changed the base branch from main to 1.x December 14, 2023 03:25
@timacdonald timacdonald changed the title [0.8.x] Introduce purge-orphaned-assets binary [1.x] Introduce purge-orphaned-assets binary Dec 14, 2023
@timacdonald timacdonald changed the title [1.x] Introduce purge-orphaned-assets binary [1.x] Introduce clean-orphaned-assets binary Dec 14, 2023
@taylorotwell taylorotwell merged commit b77e7ad into 1.x Dec 14, 2023
3 checks passed
@timacdonald timacdonald deleted the clean branch December 14, 2023 23:24
@francoism90
Copy link

francoism90 commented Dec 19, 2023

@timacdonald Would you recommend running npx clean-orphaned-assets for production/on deployment?

Thanks!

@timacdonald
Copy link
Member Author

@francoism90 I would. You should use --dry-run first to make sure it is going to delete what you expect. Will have docs shortly.

It is only really useful if you are also using the --emptyOutDir=false when building your assets.

tisnamuliarta referenced this pull request in tisnamuliarta/laravel-shadcn Mar 11, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://togithub.com/laravel/vite-plugin) |
[`^0.8.0` ->
`^1.0.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/1.0.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v1.0.2`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v102---2024-02-28)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.1...v1.0.2)

- \[1.x] Fix HMR issue when `resources/lang` directory doesn't exist and
a symlink is present in the root directory by
[@&#8203;jessarcher](https://togithub.com/jessarcher) in
[https://github.com/laravel/vite-plugin/pull/285](https://togithub.com/laravel/vite-plugin/pull/285)

###
[`v1.0.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v101---2023-12-27)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.0...v1.0.1)

- \[1.x] Simpler conditional by
[@&#8203;Jubeki](https://togithub.com/Jubeki) in
[https://github.com/laravel/vite-plugin/pull/273](https://togithub.com/laravel/vite-plugin/pull/273)
- \[1.x] Account for imported CSS files while cleaning by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/275](https://togithub.com/laravel/vite-plugin/pull/275)
- \[1.x] Fix exit error messages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/276](https://togithub.com/laravel/vite-plugin/pull/276)

###
[`v1.0.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v100---2023-12-19)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.1...v1.0.0)

- \[1.0] Drop CJS build and export types first by
[@&#8203;benmccann](https://togithub.com/benmccann) in
[https://github.com/laravel/vite-plugin/pull/235](https://togithub.com/laravel/vite-plugin/pull/235)
- \[1.x] Introduce `clean-orphaned-assets` binary by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/251](https://togithub.com/laravel/vite-plugin/pull/251)
- \[0.8.x] Respect vite server.origin in viteDevServerUrl by
[@&#8203;nurdism](https://togithub.com/nurdism) in
[https://github.com/laravel/vite-plugin/pull/255](https://togithub.com/laravel/vite-plugin/pull/255)
- \[1.x] Vite 5 by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/269](https://togithub.com/laravel/vite-plugin/pull/269)
- \[0.8.x] Fallback pages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/271](https://togithub.com/laravel/vite-plugin/pull/271)
- \[1.x] Auto detect Valet / Herd TLS certificates by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/180](https://togithub.com/laravel/vite-plugin/pull/180)

###
[`v0.8.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/241](https://togithub.com/laravel/vite-plugin/pull/241)
- Upgrade vitest by
[@&#8203;sapphi-red](https://togithub.com/sapphi-red) in
[https://github.com/laravel/vite-plugin/pull/246](https://togithub.com/laravel/vite-plugin/pull/246)

###
[`v0.8.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://togithub.com/AshboDev) in
[https://github.com/laravel/vite-plugin/pull/231](https://togithub.com/laravel/vite-plugin/pull/231)
- Support Laravel Herd by
[@&#8203;claudiodekker](https://togithub.com/claudiodekker) in
[https://github.com/laravel/vite-plugin/pull/233](https://togithub.com/laravel/vite-plugin/pull/233)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
tisnamuliarta referenced this pull request in tisnamuliarta/laravel-shadcn Mar 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://togithub.com/laravel/vite-plugin) |
[`^0.7.5` ->
`^1.0.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/1.0.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v1.0.2`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v102---2024-02-28)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.1...v1.0.2)

- \[1.x] Fix HMR issue when `resources/lang` directory doesn't exist and
a symlink is present in the root directory by
[@&#8203;jessarcher](https://togithub.com/jessarcher) in
[https://github.com/laravel/vite-plugin/pull/285](https://togithub.com/laravel/vite-plugin/pull/285)

###
[`v1.0.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v101---2023-12-27)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.0...v1.0.1)

- \[1.x] Simpler conditional by
[@&#8203;Jubeki](https://togithub.com/Jubeki) in
[https://github.com/laravel/vite-plugin/pull/273](https://togithub.com/laravel/vite-plugin/pull/273)
- \[1.x] Account for imported CSS files while cleaning by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/275](https://togithub.com/laravel/vite-plugin/pull/275)
- \[1.x] Fix exit error messages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/276](https://togithub.com/laravel/vite-plugin/pull/276)

###
[`v1.0.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v100---2023-12-19)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.1...v1.0.0)

- \[1.0] Drop CJS build and export types first by
[@&#8203;benmccann](https://togithub.com/benmccann) in
[https://github.com/laravel/vite-plugin/pull/235](https://togithub.com/laravel/vite-plugin/pull/235)
- \[1.x] Introduce `clean-orphaned-assets` binary by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/251](https://togithub.com/laravel/vite-plugin/pull/251)
- \[0.8.x] Respect vite server.origin in viteDevServerUrl by
[@&#8203;nurdism](https://togithub.com/nurdism) in
[https://github.com/laravel/vite-plugin/pull/255](https://togithub.com/laravel/vite-plugin/pull/255)
- \[1.x] Vite 5 by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/269](https://togithub.com/laravel/vite-plugin/pull/269)
- \[0.8.x] Fallback pages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/271](https://togithub.com/laravel/vite-plugin/pull/271)
- \[1.x] Auto detect Valet / Herd TLS certificates by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/180](https://togithub.com/laravel/vite-plugin/pull/180)

###
[`v0.8.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/241](https://togithub.com/laravel/vite-plugin/pull/241)
- Upgrade vitest by
[@&#8203;sapphi-red](https://togithub.com/sapphi-red) in
[https://github.com/laravel/vite-plugin/pull/246](https://togithub.com/laravel/vite-plugin/pull/246)

###
[`v0.8.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://togithub.com/AshboDev) in
[https://github.com/laravel/vite-plugin/pull/231](https://togithub.com/laravel/vite-plugin/pull/231)
- Support Laravel Herd by
[@&#8203;claudiodekker](https://togithub.com/claudiodekker) in
[https://github.com/laravel/vite-plugin/pull/233](https://togithub.com/laravel/vite-plugin/pull/233)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzguMSIsInVwZGF0ZWRJblZlciI6IjM3LjIzOC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants