Do you want to request a feature or report a bug?
Feature
What is the current behavior?
There appears to only be one entrypoint: index.js
If the current behavior is a bug, please provide the steps to reproduce.
n/a
What is the expected behavior?
Ability to have multiple entrypoints that will be compiled into separate files
If this is a feature request, what is motivation or use case for changing the behavior?
We're currently using preact-cli primarily for templating and do not need routing and static components in the bundle file. To keep things lean we are looking to generate separate .js files to use on pre-rendered built pages, where only the dynamic components we require are output. On other webpack projects we've achieved this by adding an additional entrypoint in the webpack.config.js file.
We are struggling to achieve something similar using preact-cli. We've tried adding another record to the config.entry within preact.config.js and whilst the code in our new entrypoint runs on serve, it errors on build.
I appreciate our use case is pretty bespoke, but it there any way to add an additional entrypoint that will be generated as is own file on build (whilst maintaining pre-rendering)?
Please mention other relevant information.
The app only works with our entry file, because the internal entry.js has the App initializer. You could hypothetically replace it with your own, and then include that on every new "manual" entry file, but then your route-to-route updates would be broken, I think.
You might be fine just using the built-in setup, prerendering multiple routes, and then creating a quick little Webpack plugin that, on after-emit, looks at a Manifest file for the route-specific file and appends it to the prerendered markup.
It'll still do an async-loaded chunk, but the chunk is already loaded.
I'm interested in this issue as well. I'm trying to build a Chrome extension with preact (and preact-cli), and the build should have two independent pages as a result. I'm new to webpack and preact, would you recommend me to use webpack by itself without preact-cli?
You can use bundle-loader to create & dynamically import the second entry.
import foobar from 'bundle-loader?name=SECOND.js!./my-entry';
You can also rely on webpack's require.ensure and dynamically load / hand-off the application as needed.
Thanks for the fast reply! I've decided to go without preact-cli for this situation anyway, because Chrome doesn't allow inline scripts. I'll keep your advice handy for futures projects.
I'd like to be able to do this. I'm investigating creating a project where preact is used on the frontend for each page of my app, but the app is not a SPA. It would be nice to be able to assemble a project into multiple standalone preact applications so that one could be used on each page 馃檪
The app only works with our entry file, because the internal
entry.jshas the App initializer. You could hypothetically replace it with your own, and then include that on every new "manual" entry file, but then your route-to-route updates would be broken, I think.You might be fine just using the built-in setup, prerendering multiple routes, and then creating a quick little Webpack plugin that, on
after-emit, looks at a Manifest file for the route-specific file and appends it to the prerendered markup.It'll still do an async-loaded chunk, but the chunk is already loaded.
I'm having this issue, where changing the preact-cli-entrypoint makes preact-router to stop working properly. I haven't been able to find much about this issue online. Any further ides on how to set it up so that preact-router would work properly when changing the entry point?
Most helpful comment
I'd like to be able to do this. I'm investigating creating a project where preact is used on the frontend for each page of my app, but the app is not a SPA. It would be nice to be able to assemble a project into multiple standalone preact applications so that one could be used on each page 馃檪