Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

tyler36/browsersync-demo

Repository files navigation

Browsersync with DDEV

Intro

This project is designed as a demo for BrowserSync with DDEV.

It is based on Laravel 9. It runs BrowserSync through laravel-mix.

Requirements

  • PHP 8
  • DDEV 1.19

Setup

  • Clone project
  • Start DDEV
ddev start
  • Install depenendencies & packages
ddev composer install
ddev ssh
npm install
  • Copy .env.example to .env
cp .env.example .env
  • Add Laravel key
php artisan key:generate

Demo 1: Host with artisan server

Confirm browser sync works on host.

  • Run Laravel's serer
php artisan serve
  • In a seperate terminal, run laravel-mix watcher
npm run watch

DDEV & Laravel mix

  • Install NPM packages in DDEV
ddev exec npm install
  • Add browsersync to Laravel Mix's ./webpack.mix.js
    • Replace $DDEV_HOSTNAME with your site's hostname.
let url = $DDEV_HOSTNAME;

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        //
    ])
    .browserSync({
        proxy: url,
        host:  url,
        open:  false,
    });
  • Run the watcher. Note: On the first attempt, Laravel-mix may download additional required packages.
$ ddev exec npm run watch
webpack compiled successfully
[Browsersync] Proxying: http://browsersync-demo.ddev.site
[Browsersync] Access URLs:
 ---------------------------------------------------
       Local: http://localhost:3000
    External: http://browsersync-demo.ddev.site:3000
 ---------------------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
  • Due to the the way DDEV router works you must access the site via HTTPS
    • EG. https://browsersync-demo.ddev.site:3000

Errors

'400 Bad Request: The plain HTTP request was sent to HTTPS port'

  • Access the site via HTTPS, and not the HTTP address shown.EG.
    • http://browsersync-demo.ddev.site:3000
    • https://browsersync-demo.ddev.site:3000

This is due to how DDEV router works.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published