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

Allow manifest.ts to be an entry for config-webextension #8594

Closed
everdimension opened this issue Nov 1, 2022 · 5 comments
Closed

Allow manifest.ts to be an entry for config-webextension #8594

everdimension opened this issue Nov 1, 2022 · 5 comments

Comments

@everdimension
Copy link

🙋 feature request

Currently, it's only possible to have a static manifest.json file as an entry for @parcel/config-webextension config.

This makes it hard to have some conditional configuration for development and production.

If manifest.ts was allowed as an entry, it would be trivial to accomplish this.

💻 Examples

For my case, I want content_scripts policies to be different for development and production environments. I.e. I want to be able to write something like this:

"content_scripts": [{
  ...,
  "matches": ENV === 'production' ? ["https://*/*"] : ["http://*/*", "https://*/*"],
}]

Thanks!!

@everdimension
Copy link
Author

Related: #8404

@mischnic
Copy link
Member

mischnic commented Nov 3, 2022

You can preprocess the manifest with some other transformer before the builtin transformer sees it. And I think something more declarative would be better instead of allowing arbitrary Javascript (which is another whole can of worms). E.g. some kind of template syntax in strings that gets replaced (similar to EJS/Nunjucks/...).

@everdimension
Copy link
Author

@mischnic Hello, thank you for replying!

I do not consider template syntax as a better solution than arbitrary javascript. It's natural to write config in code.

But if one decides to go this way, then I think github action expression syntax can be used as inspiration.


You can preprocess the manifest with some other transformer before the builtin transformer sees it

Can you please provide an example of how this can be done? I'm not very familiar with parcel's transformer pipeline.

@mischnic
Copy link
Member

{
  "extends": "@parcel/config-webextension",
  "transformers": {
    "manifest.json": ["parcel-transformer-something", "..."]
  }
}

(the "..." will cause it to continue with the existing webext transformer)
parcel-transformer-something then does

const {Transformer} = require('@parcel/plugin');

module.exports = new Transformer({
  async transform({asset}) {
    let code = await asset.getCode();
    asset.setCode(applySomeTemplating(code));
    return [asset];
  }
});

(see https://parceljs.org/plugin-system/transformer/)

@101arrowz
Copy link
Member

Duplicate of #8138

@101arrowz 101arrowz marked this as a duplicate of #8138 Jun 3, 2023
@101arrowz 101arrowz closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2023
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