Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple entry points with Snowpack

Tags:

snowpack

I'm looking to switch from Webpack to Snowpack for a development environment. But I have multiple entry points set up in Webpack and I haven't been able to find an example of how to do this in Snowpack. It seems that Snowpack is meant to be used with a true SPA that has only one HTML page and one entry point Javascript file.

Each HTML page on the site (20 altogether) has its own index.js that is the starting point for that page and is independent from the other pages on the site. How would this work in Snowpack?

I found some discussions on Github about multiple entry points, but reading through the comments I wasn't able to determine if this is supported or not. If it isn't supported, would I need to run Snowpack for each index.js? Or is there another fast development tool that would work in this use case?

like image 588
DavGarcia Avatar asked Nov 07 '22 01:11

DavGarcia


1 Answers

If you check the config documentation, you will see the mount option is an object, meaning you mount multiple directories. If you have multiple top level modules in a mounted directory, you will get multiple entry points.

For example, following configuration takes any module from src folder and outputs it to dist folder in your build directory:

mount: {
  src: { url: '/dist' },
},

Say you have src/index.tsx and src/module.tsx files, you will get dist/index.js and dist/module.js files in your output directory.

I just tested and it works.

like image 57
snnsnn Avatar answered Nov 25 '22 20:11

snnsnn