Code Monkey home page Code Monkey logo

Comments (6)

developit avatar developit commented on May 25, 2024

It's required for webpack HMR, since import is only allowed at the top level. Sadly System.import() won't work there either because of how webpack parses require() statements in the HMR callback. Cheers!

from preact-boilerplate.

developit avatar developit commented on May 25, 2024

To clarify: require() is the only way to do this because it's the only way to obtain the updated module definition from webpack.

from preact-boilerplate.

silverlight513 avatar silverlight513 commented on May 25, 2024

You could have a simple express server with the webpack-dev-middleware and webpack-hot-middleware. That way you can use imports across the whole project.

Adding a simple express server means that server side rendering could be added with react-dom/preact-compat.

from preact-boilerplate.

developit avatar developit commented on May 25, 2024

That would not solve the issue. This is already using webpack-dev-middleware - that's what powers webpack-dev-server. webpack-hot-middleware doesn't help here either - as stated in their readme, it's still up to the application to update in response to HMR.

Basically, something has to re-import the root module in order to re-render it. Can't do that with ES Modules.

For what it's worth though, I do want to get rid of the manual implementation (because I agree, it's awkward to have both types of imports in one file). I've been looking into making Preact work out-of-the-box with React Hot Loader, which would make all of the manual HMR stuff unnecessary.

from preact-boilerplate.

silverlight513 avatar silverlight513 commented on May 25, 2024

In my side project I'm using HMR with an express server in which I'm not using require at all. I'm not 100% sure how it works as I used a boilerplate and just tweaked it. I'll take a look at what I'm doing and see if I can come up with a viable solution. If I do find something, would it be okay to make a PR?

from preact-boilerplate.

developit avatar developit commented on May 25, 2024

Sure, but drop me a line first via Twitter or the Preact slack if you find something - want to make sure first. It's possible your setup is using HMR but not actually re-rendering components in response to HMR, or that it doesn't account for the root component changing.

from preact-boilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.