Languages
[Edit]
EN

Preact - multiple entry points with multiple builds (multiple index file)

7 points
Created by:
Root-ssh
178170

In this short article, we would like to show how to configure Preact to work with multiple entry points.

Warning: by default Preact does not provide multiple entry points, so we need to do some trick.

 

Simple steps

Edit

Before we will start: multiple entry points usage, causes multiple builds to get a proper working application variant. This way each build contains only necessary source code (only specific imports).

1. Use --dest parameter to run specific build variant:

Edit

 

2. Configure preact.config.js file located directly in the project directory.

Edit

Explaination: having access to --dest argument as env.dest property, we should update the following WebPack configuration:

  • config.entry['ssr-bundle']
  • config.resolve.alias['preact-cli-entrypoint'].

Note: it is good to use config.context that indicates src/ directory.

Finally we can use the following preact.config.js file:

 

3. Create multiple indexes, e.g.

Edit
  • src/index-1.jsx,
  • src/index-2.jsx,
  • src/index-N.jsx.

From now src/index.jsx will be used to start specific development version, e.g.:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join