How can I access target name in a Parcel plugin?

Viewed 59

I'm using Parcel for a web extension project. I've defined 2 targets in package.json file:

"targets": {
    "firefox": {
        "engines": {
            "browsers": [
                "last 1 Firefox version"
            ]
        }
    },
    "chrome": {
        "engines": {
            "browsers": [
                "last 1 Chrome version"
            ]
        }
    }
}

I want to write a transformer (or any plugin which does the trick) to combine a manifest.json and manifest.{targetName}.json before collecting manifest dependencies.

So far I have learned that asset.env gives some info about the current environment. But I'm looking for a way to get the target name. Is there any way for it?

1 Answers

The best solution I've come up so far is to use a custom resolver. A resolver has a resolve method. One of the arguments this method accepts, is dependency which has a nullable field target. This is what I was looking for.

Then for the combining of main manifest and target-specific manifest files, I can return the JSON content of merged files inside the code field of the function output.

This works fine in the build time. But still not working when I update manifest while parcel watch is running.

Related