question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parcel 2: multi entry/target builds

See original GitHub issue

Split out of #2574.

For SSR, it would be useful to support multiple targets with different entries simultaneously.

Three options came up in the previous issue:

Explicit entries per target

const parcel = new Parcel({
  entries: {
    browserEntry_page1: '/path/to/browser/entry/of/page1.js',
    browserEntry_page2: '/path/to/browser/entry/of/page2.js',
    serverEntry: '/path/to/server.js',
  },

  targets: {
    browserEntry_page1: {
      "browsers": ["> 1%", "not dead"]
    },
    browserEntry_page2: {
      "browsers": ["> 1%", "not dead"]
    },
    serverEntry: {
      "node": ["^8.0.0"]
    },
  }
});

An array of parcel options

const parcel = new Parcel([
  {
    entries: ['page1.js', 'page2.js']
    targets: {
      browser: {
        browser: ['>1%', 'not dead']
      }
    }
  },
  {
    entries: ['server.js']
    targets: {
      node: {
        node: ['^8.0.0']
      }
    }
  }
});

Multiple Parcel instances, sharing a worker farm

We were thinking of making the worker farm an option anyway, so this might work for free. By sharing a worker farm instance, multiple Parcel instances could run in parallel.

const workerFarm = new WorkerFarm();

const browserParcel = new Parcel({
  workerFarm,
  entries: ['page1.js', 'page2.js']
  targets: {
    browser: {
      browser: ['>1%', 'not dead']
    }
  }
});

const serverParcel = new Parcel({
  workerFarm,
  entries: ['server.js']
  targets: {
    node: {
      node: ['^8.0.0']
    }
  }
});

Thoughts?

cc. @brillout @padmaia @wbinnssmith

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:23
  • Comments:50 (27 by maintainers)

github_iconTop GitHub Comments

3reactions
devongovettcommented, Nov 6, 2019

It is all possible to override, I’m just not sure we should encourage it:

{
  "main": "dist/index.html",
  "targets": {
    "main": {
      "context": "browser",
      "isLibrary": false,
      "includeNodeModules": true,
      "engines": {
        "browsers": ["> 1%"]
      }
    }
  }
}
3reactions
Banou26commented, Oct 30, 2019

@brillout I’m sorry but that’s a big no for me, this is just unnecessarily complex,

const parcel = new Parcel({
  entries: [
    {
      entry: '/path/to/page1.js',
      target: ['browser', 'node'],
    },
    {
      entry: '/path/to/page2.js',
      target: ['browser', 'node'],
    },
    {
      entry: '/path/to/server.js',
      target: 'node',
    },
  ],

  targets: {
    browser: {
      browsers: ["> 0.25%", "not dead"],
    },
    node: {
      nodejs: "^8.0.0",
    }
  }
})

Would serve the same purpose, while being more explicit and straightforward.

I don’t like the fact that you can reference targets, from targets, this makes you have to look back everytime you see a definition that use a reference. Configurations should be explicit and simple, sure, if you have a lot of different needs, it’ll get complex, but for a simple configuration like this, it shouldn’t be and look complex for nothing.

Edit 1: BTW, about your isomorphic target, if parcel supports ESM outputs and the top level await proposal(which is getting shipped in v8 and webpack as an experiment), we could have multi-target bundles since node will, at its next version, support ESM modules as a stable feature

Edit 2: While we’re at it, we could even remove some config duplication by allowing entries as array, but then i’m not sure that entries/entry/target should be the name of the properties

const parcel = new Parcel({
  entries: [
    {
      entry: ['/path/to/page1.js', '/path/to/page2.js'],
      target: ['browser', 'node'],
    },
    {
      entry: '/path/to/server.js',
      target: 'node',
    },
  ],

  targets: {
    browser: {
      browsers: ["> 0.25%", "not dead"],
    },
    node: {
      nodejs: "^8.0.0",
    }
  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Targets - Parcel
Parcel can compile your source code in multiple different ways simultaneously. These are called targets. For example, you could have a “modern” target...
Read more >
Devon Govett Twitterissä: "Parcel 2 supports multi-target ...
Parcel 2 supports multi-target builds. Just set them up in your package.json, and Parcel will build multiple versions of your app in parallel....
Read more >
package.json - Parcel
To create your own target (without any of the semantics of the common target described previously), add a top-level field with your target's...
Read more >
Bundling and Building with Parcel - Beginner JavaScript
However, for longer projects that span multiple days, it is best you install Parcel to ... (Note: if you see Parcel 2 as...
Read more >
deploying problem with multiple html files. Parcel
when I deploy a website( with multiple entry points, many HTML files ) and the host uses the build command: parcel build index.html ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found