Skip to content

Unlinking md/vue file will cause an temporary webapck error #351

Closed
@ulivz

Description

@ulivz
  • Your OS: OSX 10.12.6
  • Node.js version: 9.4.0
  • VuePress version: 0.8.4

Summary

This issue was found by @meteorlxy at #348

unlinking a markdown/component file will cause an webapck error first, and then successfully compiled after the prepare finish.

Why having this bug?

Let me take a vue component file as an example.

  1. When you add a new component, chokidar catch the add event, and re-generated the temp files. so the process is:
add compoennt 
      => update by chokidar => temp file change => webpack HMR
  1. When you delete the component you just added, first, webpack catch the unlink event immediately and tried to run HMR, but an linked module was missing so an error will be emitted soon, At the same time the chokidar catch the unlink event too, after several ms, temp files are re-generated, so webpack will update again, then the error disappeared. so the process is:
delete component 
      => webpack HMR => emit error.
      => update by chokidar => .... => temp file change => webpack HMR => error fixed.

Workaround

Exclude the files at docs/** in webpack and add change event to chokidar. then the process will be:

delete component 
      => update by chokidar => .... => temp file change => webpack HMR => error fixed.

But this solution has a side effect is that when you only typed some words, update by chokidar will be re-run.

Ideal workaround

if webpack watchOptions can support conditional ignore, there will be a perfect fix:

  • change => webpack HMR
  • add/unlink/addDir/unlinkDir => only update by chokidar (disable webpack HMR)

I just checked the watchpack:

https://github.com/webpack/watchpack/blob/8d839e8b6edb87f9cd8a1ff97028060c4ecc9bee/lib/DirectoryWatcher.js#L67-L72

And also checked webpack's docs / code but didn't find any approach.

cc @yyx990803

Metadata

Metadata

Assignees

Labels

type: enhancementRequest to enhance an existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions