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

Dynamic entry with using devMiddleware.invalidate will not generate the new html #1722

Closed
moyueating opened this issue Jan 27, 2022 · 2 comments

Comments

@moyueating
Copy link

moyueating commented Jan 27, 2022

Currently using webpack5, html-webpack-plugin, I want to achieve incremental compilation through dynamic entry, but when I trigger the update through devmiddleware.invalidate(), I only get the compiled js and css files but not the expected html files. The following is the general configuration and usage.

let cacheEntries = [ 'pages/page1/main.js' ] 

module.exports = {
    entry = () => cacheEntries,
    optimization: {
         runtimeChunk: 'single'
    },
    devServer: {
         onBeforeSetupMiddleware: devServer => {
             const app = devServer.app;
             const compiler = devServer.compiler 
             const devMiddlewareInstance = devServer.middleware
             app.use((req, res, next) => {
                      cacheEntries['page2'] = [path.resolve(process.cwd(), `./src/pages/page2/main.js`)]
                      new HTMLWebpackPlugin({
                           filename: 'page2/index.html',
                           template: path.resolve(process.cwd(), './public/index.html')  
                      }).apply(compiler)
                      devMiddlewareInstance.invalidate()
            })
        }
    }
}

Then I looked at the source code of html-webpack-plugin and found that entryOptions is handled on the hook of compiler.initialize. Does this mean that dynamic entry is not supported? If it is really not supported, is there any good way for the implementation of dynamic entry incremental compilation?

image

Looking forward to your answer, thanks!

@DaveDev13
Copy link

@jantimon Hi, I also faced such a problem, can you tell me?

@alexander-akait
Copy link
Collaborator

I want to close this in favor of #1768, because html-webpack-plugin uses hook to init options, it doesn't work dynamically right now (more context - webpack/webpack#16312 (comment)), I want to fix it soon

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

No branches or pull requests

3 participants