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

Better SSR support [watch build] #972

Closed
surmon-china opened this issue Oct 27, 2020 · 7 comments
Closed

Better SSR support [watch build] #972

surmon-china opened this issue Oct 27, 2020 · 7 comments

Comments

@surmon-china
Copy link
Contributor

surmon-china commented Oct 27, 2020

Feature

I am using vite to build an SSR website, during which I tried to implement a nuxt-like, faster SSR framework, but I need better support.

I wish build and ssrBuild can support watch mode, or there be watchBuild and watchSSRBuild functions

SSR inevitably requires real-time compilation of products (Client & Server)

In my test.

First, a form of fileWatcher(files, () => build().then(() => restart())) is used to track file changes and execute compile, but this will do a full build without cache support, which takes a long time.

const watcher = chokidar.watch(path.resolve(__dirname, 'src'), {
  ignored: [/node_modules/, /\.git/],
  awaitWriteFinish: {
    stabilityThreshold: 100,
    pollInterval: 10
  }
})

watcher.on('change', info => {
  ssrBuild({/* ... */})
})

Second. If you use rollup.watch to compile, you can quickly update the product and achieve a better development experience.

const rullupConfig = {
    input: path.resolve(root, entry),
    preserveEntrySignatures: false,
    ...rollupInputOptions,
    // ...
}

 const watcher = rollup.watch({
    ...rullupConfig,
    output: {
        // ...
        ...rollupOutputOptions
    },
    watch: {
        ...rollupWatchOptions
        chokidar: chokidar.watch(/* watchPath */, {
            ignored: [/node_modules/, /\.git/],
            awaitWriteFinish: {
                stabilityThreshold: 100,
                pollInterval: 10
            }
        }),
    }
})


watcher.on('event', event => {
    if (event.code === 'BUNDLE_END') {
        doRestart()
        // emit something...
        // write files...
        // ...
    }
});

However, the implementation of the build function in the vite src/node/build/index.ts:build file is too complex and deeply coupled, and I have to re-implement it externally, so I hope this can be extracted as a single function.

links

@aleclarson
Copy link
Member

Watch support for build would also be super useful when working on legacy bundles (via vite-plugin-legacy).

@surmon-china surmon-china changed the title Better SSR support Better SSR support [watch mode] Oct 28, 2020
@surmon-china surmon-china changed the title Better SSR support [watch mode] Better SSR support [watch build] Oct 28, 2020
@surmon-china
Copy link
Contributor Author

I can submit a pull request to implement this feature.

@yyx990803 @antfu @underfin

@TechAkayy
Copy link

TechAkayy commented Nov 1, 2020

vite build --watch (defaulted to dev mode) will be very invaluable...

Similar to.. @surmon-china

vite build --watch --hmr like snowpack (FredKSchott/snowpack#1002) would be the ultimate...

@arpowers
Copy link
Contributor

arpowers commented Nov 19, 2020

@surmon-china any updates on the PR?

I've taken a look at Vite source and I agree this would be a pretty simple change. Basically, Rollup should just run rollup.watch instead of rollup.rollup if we are in NODE_ENV=development mode. From there, I think we would be able to add the standard watch options via the existing rollup options.

I would do the PR myself but I can't figure out exactly how I'm supposed to run the playground, testing, and dev server to create an acceptable result... For someone experienced with the codebase, any thoughts?

@cawa-93
Copy link
Contributor

cawa-93 commented Nov 20, 2020

watch support for build would also be super useful when you develop electron app.

@wxs77577
Copy link

wxs77577 commented Jan 5, 2021

Any update on this feature?

@yyx990803
Copy link
Member

Closing to track in #1290 & #1434

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants