question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In v6, when using `npm run hot`, bundled files are not written into public folder but are still served correctly

See original GitHub issue
  • Laravel Mix Version: 6.0.9 (npm list --depth=0)
  • Node Version (node -v): 12.20.0
  • NPM Version (npm -v): 6.14.9
  • OS: Windows 10

Context:

I have a blade component that automatically injects scripts and styles by name when called:

{{-- asset-injector.blade.php --}}

@props(['name' => ''])

@if(isset($name) && !empty($name))
  @if (file_exists(public_path("js/$name.js")))
    @push('scripts')
      <script src="{{ mix("js/$name.js") }}" defer></script>
    @endpush
  @endif
  @if (file_exists(public_path("css/$name.css")))
    @push('styles')
      <link rel="stylesheet" href="{{ mix("css/$name.css") }}">
    @endpush
  @endif
@endif


{{-- example.blade.php --}}

<div class="any-component>
  @once
    {{-- Automatically injects corresponding "example.js" and "example.css" if exists  --}}
    <x-asset-injector name="example" />
  @endonce
</div>

Description:

Just upgraded to version 6 from version 5.

In version 5, when I run npm run hot, bundled files will be written into public folder (or whatever folder set by mix.setPublicPath).

That is not the case anymore in version 6.

In version 6, when I run npm run hot, the files are bundled, but are not being written into the public folder.

The files are still served correctly with mix('path/to/file'). The problem is that it is not writing into public folder anymore, so that the file_exists() call in the component shown above will always be false when in hot reloading mode.

This only happens in npm run hot. When running dev, watch, and prod, the files are created and written correctly into public folder.

Question

Is this behaviour a bug or by design? If it is by design, why are we doing this and where have the bundled files gone and being served from?

Steps To Reproduce:

Run npm run hot and observe bundled files will not be created/written into public path but are still served correctly.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
thecrypticacecommented, Jan 10, 2021

Ah sorry, the webpack documentation hasn’t been updated for webpack dev server v4 configuration.

The correct version is:

mix.webpackConfig({
  devServer: {
    dev: { writeToDisk: true }
  }
})

All webpack-dev-middleware compatible configuration was removed in favor of passing it via the dev option.

0reactions
yqlimcommented, Jan 10, 2021

@thecrypticace ah I see. It works now, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React routing is not working in bundle file - Stack Overflow
I created a react-app using webpack .If I run the npm run build , build file was generated successfully but route components are...
Read more >
Mix does not delete old versioned files when a new one is ...
It works to run command like: npm run dev or prod, but for the npm run watch the same is not deleting the...
Read more >
Changelog - Cypress Documentation
Fixed an issue with Angular Component Testing where urls within SASS/SCSS files were not being correctly resolved which could result in incomplete styling....
Read more >
webpack-dev-server
This modified bundle is served from memory at the relative path specified in publicPath (see API). It will not be written to your...
Read more >
Shadow CLJS User's Guide
It is recommended to still use the shadow-cljs command to run ... They are not specific to any build and can be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found