Skip to content

feat(nuxt): add watch option and refactor dev server restarting#19530

Merged
danielroe merged 4 commits into
mainfrom
feat/watch
Mar 9, 2023
Merged

feat(nuxt): add watch option and refactor dev server restarting#19530
danielroe merged 4 commits into
mainfrom
feat/watch

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This provides a number of improvements to the dev server restarting behaviour:

  1. it allows configuring the files that cause a server restart (with either string/RegExp - more complex patterns can be handled with builder:watch hook
  2. it fixes implementation detail where we were only listening in dev server to rootDir changes, but we were trying to match against srcDir - this would have worked unless there was a custom srcDir (an undetected bug?)
  3. it now offers more precise matching in pages module to detect changes and trigger restart
  4. we now support restarting on actual component/composables/utils directories that are used rather than hard-coded values

What's more, because we're moving the logic into the ad-hoc modules that actually care about this, it should mean we integrate better with upcoming nuxi-ng, but definitely cc: @pi0 in case you foresee any issues here.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added ✨ enhancement New feature or improvement to existing functionality 3.x labels Mar 8, 2023
@danielroe danielroe requested review from antfu and pi0 March 8, 2023 16:18
@danielroe danielroe self-assigned this Mar 8, 2023
@codesandbox

codesandbox Bot commented Mar 8, 2023

Copy link
Copy Markdown

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@atinux atinux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better now and also bringing back a needed feature from Nuxt 2 to Nuxt 3 (ie: Tailwind module for instance)

@danielroe danielroe merged commit 9036142 into main Mar 9, 2023
@danielroe danielroe deleted the feat/watch branch March 9, 2023 11:46
@danielroe danielroe mentioned this pull request Mar 10, 2023
@mcfarljw

Copy link
Copy Markdown

This feature hasn't been added to the documentation yet.

@KnifeFed

Copy link
Copy Markdown

How do you use this? I tried all imaginable combinations of watch: ['tailwind.config.ts'] but it's not restarting the server when changing the file.

@danielroe

Copy link
Copy Markdown
Member Author

@KnifeFed Those paths need to be absolute. I've merged a fix to allow you to use paths relative to your srcDir, which will be included in the next patch release.

@FreekVR

FreekVR commented Jun 26, 2023

Copy link
Copy Markdown

Is the fix for relative paths confirmed to be merged?

I've tried every variation, but the watcher only works with abspath for me on nuxt 3.6.0

    watch: [
        '/assets/styles/css-variables.js'
    ],
    watch: [
        './assets/styles/css-variables.js'
    ],
    watch: [
        'assets/styles/css-variables.js'
    ],
    watch: [
        '@/assets/styles/css-variables.js'
    ],

@danielroe

Copy link
Copy Markdown
Member Author

@FreekVR Yes, this was merged. If you are experiencing a regression, please do open a new issue with a reproduction.

@plcdnl

plcdnl commented Jul 23, 2023

Copy link
Copy Markdown

I'm so sorry but i'm trying to do it with nuxt 3.6.5 and it doesn't restart the app. Both with the absolute url and with the relative one

@danielroe

Copy link
Copy Markdown
Member Author

Let's track in #22272.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x ✨ enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants