Friday, October 4, 2024
HomePHPAssist for Bun lands in Laravel Sail and Forge

Assist for Bun lands in Laravel Sail and Forge


Each Laravel Sail and Laravel Forge now contains help for Bun, a quick all-in-one JavaScript runtime. When you replace Sail, you can begin Bun as follows:

sail bun run ... # Run a `bun` command

sail bunx ... # Run a `bunx` command

Bun is a brand new all-in-one toolkit for JavaScript and TypeScript apps that ships with a single executable, aptly named bun. Like npx, the bunx runs an NPM package deal executable and robotically installs the package deal to a worldwide shared cache if not put in in node_modules.

Let’s take a look at how we are able to use bun with Sail or any Laravel challenge.

Utilizing Bun in Your Laravel Venture

To start out utilizing Bun with Laravel, you will first need to take away the present package-lock file. For instance, if you happen to’re utilizing npm, you will need to run the next:

# Take away package-lock.json

git rm package-lock.json

git commit -m"Take away package-lock.json" package-lock.json

 

# Set up dependencies with bun

sail bun set up

[1.30ms] ".env"

bun set up v1.0.0 (822a00c4)

 

Checked 20 installs throughout 43 packages (no modifications) [41.00ms]

After the bun set up succeeds, you possibly can model the lock file:

git add bun.lockb

git commit -m"Set up Bun" bun.lockb

Set up Packages with Bun

You may also use the bun set up command so as to add new dependencies. To illustrate you need to set up the laravel-precognition-vue package deal with Laravel Precognition:

$ sail bun set up laravel-precognition-vue

 

[1.05ms] ".env"

bun add v1.0.0 (822a00c4)

 

put in laravel-precognition-vue@0.5.1

 

 

9 packages put in [1.57s]

The construct and dev command with Vite

You should utilize bun to run the construct command that builds Vite dependencies for manufacturing:

$ sail bun run construct

$ vite construct

vite v4.4.9 constructing for manufacturing...

✓ 46 modules reworked.

public/construct/manifest.json 0.25 kB │ gzip: 0.13 kB

public/construct/property/app-4ed993c7.js 0.00 kB │ gzip: 0.02 kB

public/construct/property/app-dbe23e4c.js 29.10 kB │ gzip: 11.64 kB

✓ in-built 1.07s

On your growth workflow, you possibly can run the dev command the identical manner:

sail bun run dev

Updating Sail

To get the newest model of Laravel Sail in your present utility, replace Sail by way of composer:

composer replace larvel/sail

git add composer.lock

git commit -m"Replace sail" composer.json

 

# Construct the newest Docker photos

sail down

sail construct --pull

sail up -d

As soon as you’ve got constructed the newest model of Sail, you possibly can confirm that bun is put in with the next:

sail bun --version

1.0.0

Hat tip to Dmytro Morozov, who contributed Bun help! See laravel/sail Pull Request #616 for extra particulars.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments