Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack): HMR not work on Windows #3495

Merged
merged 1 commit into from
Jan 25, 2024
Merged

fix(webpack): HMR not work on Windows #3495

merged 1 commit into from
Jan 25, 2024

Conversation

anyesu
Copy link
Contributor

@anyesu anyesu commented Jan 7, 2024

Describe


Unplugin will also normalize absolute path since 0.9.0 .

ref:

Reproduction


  • On Windows .

  • Use vue-cli5 with default css.extract ( false ) .

    - css: {
    -   extract: process.env.NODE_ENV === 'development'
    -     ? {
    -         filename: 'css/[name].css',
    -         chunkFilename: 'css/[name].css',
    -       }
    -     : true,
    - },

You can see it when debugging:

  • The path in updateModules is /__uno.css .

  • The id in load is \__uno.css which use backslash , so the hash is always undefined .

image

PS


This normalizeAbsolutePath is really bad, it only works on absolute paths on Windows ( but the /foo/bar is not strictly a Windows absolute path ) , and is meaningless for other situations.

Now some places use normalizeAbsolutePath for conversion, and some places are missing, which makes it very confusing. This is very unfriendly to Windows users , because some inexplicable problems always occur due to missing conversions in some places, and it is very difficult to troubleshoot the problem.

My opinion: if all places where paths are used are converted to slashes or relative paths relative to the project root, then if you see backslashes, you can quickly realize that there is a problem here.

@anyesu anyesu requested a review from antfu as a code owner January 7, 2024 09:15
Copy link

netlify bot commented Jan 7, 2024

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cda1d7e
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/659a6b9fa6928e0008a0521b
😎 Deploy Preview https://deploy-preview-3495--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@anyesu
Copy link
Contributor Author

anyesu commented Jan 7, 2024

Another problem is that the reload of uno.css will not be triggered until the next compilation. The load hook is always called before writeModule and will not be called again after it.

<template>
  <div id="app" class="bg-red w-100px">hello</div>
</template>

Change the w-100px in App.vue by following steps:

w-200px                            // not reload, width: 100%
add a space to trigger compilation // reload
w-300px                            // not reload, width: 100%
w-400px                            // reload
w-500px                            // reload

uno

When I add a delay to writeModule ( it seems to be after compilation is completed ) , everything works fine, but the delay time is difficult to judge.

+ setTimeout(() => {
    plugin.__vfs.writeModule(id, code)
+ }, 1000)

Maybe this is a problem with webpack but I know little about it.

@antfu antfu enabled auto-merge January 25, 2024 15:29
@antfu antfu added this pull request to the merge queue Jan 25, 2024
Merged via the queue into unocss:main with commit 2ac03d2 Jan 25, 2024
9 checks passed
@anyesu anyesu deleted the fix branch January 25, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants