Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel API: Allow specifying different sources per target #8684

Open
LekoArts opened this issue Dec 9, 2022 · 1 comment
Open

Parcel API: Allow specifying different sources per target #8684

LekoArts opened this issue Dec 9, 2022 · 1 comment

Comments

@LekoArts
Copy link
Contributor

LekoArts commented Dec 9, 2022

🙋 feature request

The package.json API allows specifying different sources per target: https://parceljs.org/features/targets/#package.json%23targets.*.source

{
  "targets": {
    "frontend": {
      "source": "app/index.html"
    },
    "backend": {
      "source": "api/index.js"
    }
  }
}

At the moment this isn't available with the Parcel API.

🤔 Expected Behavior

With the Parcel API you're able to define the source per target in the same way that entries works.

import {Parcel} from '@parcel/core';

let bundler = new Parcel({
  defaultConfig: '@parcel/config-default',
  mode: 'production',
  targets: {
    modern: {
      source: "**/*.js"
    },
    legacy: {
      source: "**/legacy/*.js"
    }
  }
});

😯 Current Behavior

Not available.

💁 Possible Solution

Basically the codepath in

if (target.source != null) {
targetsWithSources++;
let targetSources = Array.isArray(target.source)
? target.source
: [target.source];
let i = 0;
for (let relativeSource of targetSources) {
let source = path.join(entry, relativeSource);
let keyPath = `/targets/${targetName}/source${
Array.isArray(target.source) ? `/${i}` : ''
}`;
await assertFile(
this.options.inputFS,
entry,
relativeSource,
filePath,
keyPath,
this.options,
);
entries.push({
filePath: toProjectPath(this.options.projectRoot, source),
packagePath: toProjectPath(this.options.projectRoot, entry),
target: targetName,
loc: {
filePath: toProjectPath(
this.options.projectRoot,
pkg.filePath,
),
...getJSONSourceLocation(
pkg.map.pointers[keyPath],
'value',
),
},
});
i++;
}
also needs to happen for this.options.targets inside resolveEntry function.

Open question about this: What should happen with the top-level entries? Currently it's required but how would that play into this?

@blipper
Copy link

blipper commented May 29, 2023

Updating the API to make it clear that this can't be done would save time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants