parcel-bundler / parcel

The zero configuration build tool for the web. šŸ“¦šŸš€
https://parceljs.org
MIT License
43.43k stars 2.26k forks source link

[RFC] New Asset support via Plugins or Core? #213

Closed davidnagli closed 6 years ago

davidnagli commented 6 years ago

šŸ’¬ RFC

Do you guys think support for new things should be added to the core, or via plugins?

Currently, we have a weird mix of both:

What do you guys think?

To sum up what I heard in the slack:

Itā€™s probably going to end up being a combination of all of theseā€¦

If so, we need to decide which files should be considered ā€œcoreā€ and which ā€œpluginsā€

davidnagli commented 6 years ago

What are your guysā€™ thoughts?

dschnare commented 6 years ago

And if asset types are indeed going to be part of core, a way to list them. I tried looking for TypeScript support and I didn't know it was in core until reading this issue.

albinotonnina commented 6 years ago

To elaborate more on that, I imagine something along the lines of:

choose Image from Inquirer

and maybe utilities like: $ parcel supports --list etc

I would like this sort of granular control on this.

EduardoRFS commented 6 years ago

"The core", don't need to be the "parcel-bundler" package, perhaps the default setup contains a "lot" of plugins, like stylus, ts, jsx, and exists a "clean" package without everything, perhaps even the default css, html can be removed.

But for the tool supports a default option to setup vue and react fully support it's a cool feature

artyomtrityak commented 6 years ago

what about Flowtype? Pracel uses Babel preset-env, can babel-preset-flow be added too?

davidnagli commented 6 years ago

@artyomtrityak This doesnā€™t really have to do with Parcel pluginsā€¦ Parcel supports .babelrc, so you can add any plugins you want.

So what you said isnā€™t really relevant to this RFC šŸ˜‡ šŸ˜œ

jamiebuilds commented 6 years ago

I think that assets should probably be implemented exactly the same as plugins even if they are built-in. That way they people can use them as references

brandon93s commented 6 years ago

I think that assets should probably be implemented exactly the same as plugins even if they are built-in. That way they people can use them as references

See #251 for an example of this. Having core assets (and base types) implemented as plugins would enable these. They could just be included installed by default in parcel.

davidnagli commented 6 years ago

@thejameskyle Thatā€™s a pretty good idea. But generally how should we implement support for new Assets? Should we make these plugins part of the core, or separate?

davidnagli commented 6 years ago

I think I have a solution! It would allow us to have both a lean and minimal core, while allowing extensibility to a variety of asset types, while maintaining our zero config philosophy šŸ˜ƒ

Hereā€™s how my idea works:

At first thought, this idea of downloading plugins dynamically during build-time might seem to be prohibitively expensive. But we really only need to install these dependencies once (we can lazy-update them in the background whenever thatā€™s necessary). Also, we can have our CLI clearly show the user that weā€™re installing it for them, so they wonā€™t think that this is Parcel being slow.

Additionally, 99% of projects wonā€™t have 200 different non-standard assets. In reality, the majority of projects will not have more than 2-3 non-standard asset types at most, making the cost of dynamically installing non-standard assets in this way less of an issue, especially considering itā€™s a cost weā€™ll likely only need to pay once.

If you think about it, anyway the user is going to need to install the asset one way or the other, itā€™s just a question of whether we force them to manually install it once they need it (make everything plugins), automatically install EVERYTHING right away when they first install parcel (make everything core), or if we dynamically install plugins when they need them, without any config/setup.

  Note: I made these terms up, but:

EduardoRFS commented 6 years ago

hmm it's work, but ... isn't better at least the most popular in core? Like JSX? Isn't like 10-20 default assets gonna be so expensive in core

DeMoorJasper commented 6 years ago

Sounds like a solid idea We could probably use yarn for installing these plugins because then we don't have to worry about caching/installing or anything else. Only thing i'm mainly worried about is performance, everytime u run parcel it would have to check if u added any new assets with a new extension that has not been installed yet.

I don't know in how far this is possible but maybe we could install them while processing assets, like process the assets we can already process meanwhile install any plugin that needs to get added for the non-standard assets? Once a user adds a new asset that's not already installed, we could again install it and then compile even while running in hmr?

davidnagli commented 6 years ago

Only thing Iā€™m mainly worried about is performance, everytime u run parcel it would have to check if u added any new assets with a new extension that has not been installed yet.

@DeMoorJasper No we donā€™t! šŸ˜ƒ We just run parcel as is, and if it fails due to an unknown asset type, then we actually go ahead and try to install the corresponding asset plugin. This way we can avoid the overhead of trying to detect new asset types.

DeMoorJasper commented 6 years ago

@davidnagli will still cause worse performance but would actually only impact user if they added new extensions and once cache kicks in + all plugins installed it would actually work pretty insane fast. I'll have a spin at this way of working by first testing it on localrequire, we might even register all known extensions and localrequire the plugins as well šŸ¤” (than we are zero config/zero install?)

Although i just realised how do you detect all languages that use the same extension?

brandon93s commented 6 years ago

I'd like to propose an alternative, that may be a bit more "long-term":

All Asset Types are Plugins

  1. Asset.js and all asset implementations are extracted into their own repositories in the parcel-bundler organization. This includes their testing and necessary dependencies. This will give you repos such as:
  1. All asset types are published to NPM under the @parcel-bunder organization namespace, individually:
  1. All "core asset types" (officially supported by the parcel team) are yarn add (installed) into core (this repo) by default, as dependencies. Parcel core could reference latest (npm release) by default so it always pulls the newest version.

  2. Parcel is enhanced to look at @parcel-bundler/* dependencies (in addition to parcel-plugin-*) and treat them as plugins / register. Plugin resolution would be treated in the following order:

Advantages

Community Plugins

User land plugins can extend directly off of existing assets without the need to require the entire core bundler.

Plugins with enough community support / demand, can be installed into core as dependencies. This allows the entire community to benefit. Optionally, they can "graduate" into the organization as official assets at the creators discretion.

Instead of auto-installing or any thing along those lines, provide a sensible way to search for asset types that aren't supported out of the box (e.g. user-land plugins):

$ parcel search buckle
The following plugins match your search, use `yarn add {name}` to use them with parcel:

   1) parcel-plugin-bucklescript - A parcel plugin that enables bucklescript support

This would just search the npm registry.

rondonjon commented 6 years ago

I think a "core" should be as small as possible (that's why it's called a core), and all assets, plugins, etc. should be treated equally and separately.

Every attempt to define an "essential" set of those is inherently biased and somewhat arbitraty. A Typescript programmer might find js useless, a routined scss user will have little need for plain css. Hence it should be considered as "normal" and not as an "edge case" that people pick their extensions, and possibly also need to do that manually. It's quite a common thing, right? For babel, react, and many other popular software packages, user-selected npm i is actually the way of mapping individual needs to available features.

Yet, if a majority thinks that pre-bundling is indeed necessary, it could be an option to have something like distributions of parcel, which could then include different feature sets, e.g. just the core plus essential tools ("minimal"), or the prior plus a curated set of extensions ("standard"), or the prior plus all other officially maintained extensions ("full").

About the automatic downloads, I am not sure. It seems very convenient and seamless at first sight, but I am unsure if users actually want that, and where it could fail for reasons beyond a simple standard setup. For example, many companies use internal repositories that often require authentication. If yarn was used to silently download missing dependencies, people might need to preconfigure it appropriately, and in such cases, manual postinstallation of additional dependencies once within every couple of months really seems more straightforward. Just imagine having to write test cases for the many weird setups that people have.