Using Parcel 2 programatically #4804
-
I am trying to use However I'm running into an issue where the project's Here's roughly how I'm running Parcel: // bundle.js
let bundler = new Parcel({
defaultConfig: {
...defaultConfigContents,
filePath: require.resolve("@parcel/config-default"),
},
entries: "src/target.js",
isLibrary: true,
mode: "production",
outputFormat: "esmodule",
target: {
outputFormat: "esmodule",
distDir: "dist",
},
});
await bundler.run(); Note that the {
"name": "example-project",
"main": "src/index.js",
// ... When I run the bundling, Parcel writes each bundle to If I remove My questions:
Here's a runnable example: https://github.com/m-allanson/parcelish |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
I've looked at the code and passing a targets property in the options should cause package.json to be ignored. Not sure why this happens
https://v2.parceljs.org/plugin-system/api/#PackageTargetDescriptor is used in a package.json, where So I guess it should be an optional property here: https://v2.parceljs.org/plugin-system/api/#TargetDescriptor |
Beta Was this translation helpful? Give feedback.
-
Change for (const module in config) {
let task = async () => {
let bundler = new Parcel({
entries: config[module].entry,
target: config[module].target, // <-- here is the problem to for (const module in config) {
let task = async () => {
let bundler = new Parcel({
entries: config[module].entry,
targets: { [module]: config[module].target }, // <-- this is the fix |
Beta Was this translation helpful? Give feedback.
-
Thanks both for your replies. For anyone looking to use Parcel 2 like this, here's the working code that I ended up with: Note that Parcel has a private API In my case I was not specifying the targets correctly, so I think Parcel was falling back to checking the |
Beta Was this translation helpful? Give feedback.
-
I have a similar problem, with also a main entry in package.json that should be ignored. My setup:
calling Parcel via API:
But there is no output at all, neither in console nor are files generated. Also it seems redundant to declare entries and again in targets.
Any Ideas? |
Beta Was this translation helpful? Give feedback.
-
@ivoba Are you by any chance trying to get it to work with Electron app? That Node.js version 14.16 looks familiar :) |
Beta Was this translation helpful? Give feedback.
I've looked at the code and passing a targets property in the options should cause package.json to be ignored. Not sure why this happens
https://v2.parceljs.org/plugin-system/api/#PackageTargetDescriptor is used in a package.json, where
package.json#default
would be used as the distEntry forpackage.json#targets.default
So I guess it should be an optional property here: https://v2.parceljs.org/plugin-system/api/#TargetDescriptor