Skip to content

Migrate frontend build from laravel-mix to Vite - #1621

Merged
KodeStar merged 3 commits into
2.xfrom
feat/vite
Oct 29, 2026
Merged

KodeStar merged 3 commits into
2.xfrom
feat/vite

Conversation

@KodeStar

@KodeStar KodeStar commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Replaces laravel-mix 6 with Vite 8 and laravel-vite-plugin, which clears the 8 npm audit advisories left after #1620. They all came from laravel-mix's dependency tree (webpack-dev-server 4 / webpack-dev-middleware, and elliptic via node-libs-browser / crypto-browserify). npm audit now reports 0 vulnerabilities, with no overrides needed.

What changed

  • vite.config.js builds resources/assets/sass/app.scss and a new resources/assets/js/index.js entry into public/build/. npm run dev runs vite build --mode development, which is unminified, and that output is committed as before. npm run prod gives a minified build, npm run watch rebuilds on change, and npm run hot starts the Vite dev server.
  • index.js imports the existing plain scripts for their side effects, in the same order mix.babel() concatenated them. The scripts themselves are unchanged and still rely on globals (jQuery still loads from public/js/jquery.min.js).
  • The bundler wraps UMD libraries as CommonJS, so they no longer set their own globals. globals.js imports Sortable and Huebee and assigns them to window, and it runs before the other scripts. Huebee now comes from npm, pinned to ~2.0.0 to match the vendored build. The vendored packaged file can't be bundled because its CommonJS branch does require("ev-emitter").
  • build.target is es2015. laravel-mix ran Babel over the scripts, but Vite's default target would leave newer syntax untranspiled, for example the object spread in app.js. Module scripts already need an ES2015 browser, so this is the lowest target that makes sense.
  • postcss.config.js adds autoprefixer, which laravel-mix ran by default.
  • Both layouts/app.blade.php and layouts/users.blade.php use @vite for the CSS and JS.
  • Removed: webpack.mix.js, public/css/app.css, public/js/app.js, both mix-manifest.json files and the vendored huebee.js.

Behaviour notes

  • Script timing: @vite emits <script type="module">, which is deferred and runs in strict mode. The app scripts now run after the rest of the page has parsed, including the inline custom_js block. The Blade inline scripts all wrap their code in $(function () {...}), which still runs after the bundle. If someone's custom JavaScript uses Huebee or Sortable straight away, outside a ready handler, it would now run too early.
  • Background image: the built CSS lives in public/build/assets/ now, not public/css/. So the bg1.jpg url() changed to ../../img/bg1.jpg, and it's marked external so Vite leaves it for the browser to resolve. That matches what processCssUrls: false did, and it keeps working for subfolder installs. One catch: under npm run hot, the CSS is served from the Vite dev server, so the default background won't load there.
  • Sass deprecation warnings: current Dart Sass prints deprecation warnings for @import and lighten() during the build. These are only warnings and the build still succeeds. I left them alone because fixing them is a separate change.

CSS compared with the old public/css/app.css

  • lighten() results print as rgb(%) instead of hex. Newer Dart Sass writes colours this way, and they're the same colours.
  • The bg1.jpg path changed, as described above.
  • Vendor prefixes follow the current browserslist defaults data, not the older caniuse data the old build used. That drops -webkit-backdrop-filter and -webkit-clip-path and adds -o-object-fit. Browsers that need the dropped prefixes, such as Safari before 18 for the blur, are below the defaults threshold now.
  • Old-IE filter: progid:... values keep their single quotes, and hsla(0deg, ...) is written as hsla(0, ...). Both are formatting only.

Testing

I ran all of the checks below again after the /simplify and /code-review --fix changes.

  • Deleted the built CSS and JS, ran a clean npm ci, npm run dev and npm run lint (all exit 0), then npm audit (0 vulnerabilities).
  • ./vendor/bin/phpunit: 169 tests pass, 1 skipped.
  • Ran the app against a copy of a local SQLite database and checked it in headless Chromium:
    • Dashboard tiles render with the default background.
    • Drag-to-reorder in edit mode posts to /order, and the new order survives a reload.
    • The huebee colour picker sets the colour on both the add and edit item forms.
    • jquery-ui autocomplete on the app name field works.
    • / focuses search, and Enter opens the first matching tile.
    • /userselect (layouts/users.blade.php) renders with the Vite CSS.
    • No console errors on any page. The only console output is a Canvas2D willReadFrequently performance warning from huebee's own code.

laravel-mix 6 pulls in webpack-dev-server 4 and node-libs-browser
(elliptic via crypto-browserify), which account for the npm audit
advisories that can't be fixed while we're on it. Switching to Vite 8
with laravel-vite-plugin removes them, and npm audit now reports 0.

- vite.config.js builds resources/assets/sass/app.scss and a new
  resources/assets/js/index.js entry into public/build. `npm run dev`
  builds unminified output, which is committed as before.
- index.js imports the existing plain scripts for their side effects in
  the same order mix concatenated them. The bundler wraps UMD libraries
  as CommonJS, so globals.js imports Sortable and Huebee and puts them
  on window. Huebee now comes from npm (2.0.x, same version as the
  vendored build) because the vendored packaged file requires
  ev-emitter/unipointer in its CommonJS branch.
- postcss.config.js adds autoprefixer, which laravel-mix ran by default.
- The bg1.jpg url() is now ../../img/bg1.jpg, relative to the built CSS
  in public/build/assets, and is marked external so Vite leaves it for
  the browser to resolve as processCssUrls: false did.
- Both layouts use @Vite instead of mix()/asset().
- The package.json overrides are dropped; a fresh lockfile has no
  advisories without them.
laravel-mix ran Babel over the concatenated scripts. Vite's default
target leaves newer syntax such as object spread in place, which would
stop the whole bundle parsing on older browsers that still run module
scripts.
@KodeStar
KodeStar merged commit 8c3a84a into 2.x Oct 29, 2026
1 check passed
@LinuxServer-CI LinuxServer-CI moved this from PRs to Done in Issue & PR Tracker Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant