Gatsby: Building and deploying multiple sites within the same Gatsby app

Created on 21 Sep 2017  ยท  12Comments  ยท  Source: gatsbyjs/gatsby

I'm working on automatic page generation and deployment but need to be able to deploy to different domains.

I'd like to be able to have a dynamic number of src folders that generate a dynamic number of public folders when gatsby build is run.

I've tried to approach it by initializing several different gatsby apps and moving the node modules to a parent directory so they can share and save a lot of space, but Gatsby throws a local install was not found error.

Gatsby Version: 1.8.13
Node Version: 8.5.0
OS: macOS Sierra 10.12.6

Imagined Project Structure

|-- .cache
|
|-- public_folders
|     |-- public1
|     |
|     |-- public2
|     |
|     |-- ...
|     |
|     |-- publicN
|
|-- src_folders
|     |
|     |-- src1
|     |    |-- layouts
|     |    |-- pages
|     |
|     |-- src2
|     |    |-- layouts
|     |    |-- pages
|     |
|     |-- ...
|     |
|     |-- srcN
|     |    |-- layouts
|     |    |-- pages
|
|-- node_modules
|
|-- .gitignore
|-- gatsby-config.js
|-- gastby-node.js
  .
  .
  .

Most helpful comment

Any chance there has been progress on this topic? Struggling with this, any input appreciated! Thanks!

All 12 comments

Why not just have each site in its own directory?

That would work well too and that is what I am currently doing. The only downside is each directory needs its own node modules so it quickly takes up a lot of space.

If you could just host the node modules in the parent directory then that would solve the problem, but there currently needs to be a local install of Gatsby for it to work.

If you could just host the node modules in the parent directory then that would solve the problem, but there currently needs to be a local install of Gatsby for it to work.

Cool, would love a PR fixing this! I know @jquense has looked into this as well.

You can make a symlink in all websites directories that point to one
folder.

On Sep 21, 2017 8:00 PM, "Kyle Mathews" notifications@github.com wrote:

If you could just host the node modules in the parent directory then that
would solve the problem, but there currently needs to be a local install of
Gatsby for it to work.

Cool, would love a PR fixing this! I know @jquense
https://github.com/jquense has looked into this as well.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/2189#issuecomment-331234822,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH_TYVUfNJZN24s0-6GfDE5WHHf4ySgmks5skqROgaJpZM4Pfgaf
.

@abumalick can you detail on this ?

@clarksandholtz I'm facing the same issue, i'd love to help testing your PR.
What is your idea about the .cache folder ?

This improvement could help in having a Gatsby Build Farm with a couple dozen sites, which we plan to have.

@sebastienfi Awesome. I just forked and created a branch

I didn't have any specific ideas about the .cache folder.

I have tried using a symlink and a modified version of Gatsby and the error I'm running into now is Class constructor ProvidePlugin cannot be invoked without 'new' when I run gatsby develop.

Here's the stack trace:

โžœ  test-page git:(gatsby) โœ— gatsby develop
success delete html files from previous builds โ€” 0.028 s
success open and validate gatsby-config.js โ€” 0.005 s
success copy gatsby files โ€” 0.035 s
success source and transform nodes โ€” 0.039 s
success building schema โ€” 0.143 s
success createLayouts โ€” 0.034 s
success createPages โ€” 0.007 s
success createPagesStatefully โ€” 0.012 s
success extract queries from components โ€” 0.147 s
success run graphql queries โ€” 0.022 s
success write out page data โ€” 0.005 s
success write out redirect data โ€” 0.003 s
success update schema โ€” 0.068 s

info bootstrap finished - 3.425 s

error Class constructor ProvidePlugin cannot be invoked without 'new'


  TypeError: Class constructor ProvidePlugin cannot be invoked without 'new'

  - plugin.js:8 F
    [contra]/[webpack-configurator]/lib/resolve/plugin.js:8:33

  - plugin.js:13
    [contra]/[webpack-configurator]/lib/resolve/plugin.js:13:16

  - plugin.js:14 module.exports
    [contra]/[webpack-configurator]/lib/resolve/plugin.js:14:8

  - index.js:180 Config.resolve
    [contra]/[webpack-configurator]/index.js:180:22

  - webpack-modify-validate.js:67 _callee$
    [contra]/[gatsby]/dist/utils/webpack-modify-validate.js:67:70

  - next_tick.js:131 _combinedTickCallback
    internal/process/next_tick.js:131:7

  - next_tick.js:180 process._tickCallback
    internal/process/next_tick.js:180:9

Related GitHub Issue Threads
https://github.com/gajus/react-css-modules/issues/196
https://github.com/tvcutsem/harmony-reflect/issues/55

Something like:

mv node_modules ../
ln -s ../node_modules .

Should work

Mmhh
Maybe you will have to

cd ..
ln -s node_modules project_folder/

Symlinks have always been tricky.
You can check if the symlink is ok with ls -l

When I did the symlink, I just did
ln -s ../node_modules node_modules
but I think we would want to program a fix into Gatsby so you don't have to do a symlink each time you make a new folder.

To do a symlink programmatically in Node you can use fs.symlink(), but I think it would be best to avoid the symlink all together and just follow the node standard of searching upwards through parent directories until the proper node_module is found.

I set mine up in the opposite manner:

.
โ”œโ”€โ”€ make.ts
โ”œโ”€โ”€ activate.ts
โ”œโ”€โ”€ made
โ”‚ย ย  โ””โ”€โ”€ crucial-systems
โ”‚ย ย      โ”œโ”€โ”€ gatsby-config.js
โ”‚ย ย      โ””โ”€โ”€ src

โ”œโ”€โ”€ node_modules
โ”œโ”€โ”€ package.json

โ”œโ”€โ”€ gatsby-config.js -> /Users/crucialfelix/code/matterminds/made/crucial-systems/gatsby-config.js
โ”œโ”€โ”€ src -> /Users/crucialfelix/code/matterminds/made/crucial-systems/src


โ”œโ”€โ”€ public
โ”‚ย ย  โ”œโ”€โ”€ index.html
โ”‚ย ย  โ”œโ”€โ”€ render-page.js.map
โ”‚ย ย  โ””โ”€โ”€ static

Where make produces all the assets and config for a gatsby site. activate symlinks one of those into the root folder.

So I can activate a site, build it, upload it. Building many means looping over all, activating one at a time and building it.

Would love a docs page exploring different options for this problem but closing this for now.

Any chance there has been progress on this topic? Struggling with this, any input appreciated! Thanks!

Was this page helpful?
0 / 5 - 0 ratings