meteor / meteor-feature-requests

A tracker for Meteor issues that are requests for new functionality, not bugs.
Other
89 stars 3 forks source link

[Package][isobuild][plugin][registerCompiler] enable "multiple" compiler plugins for pre-processing files #391

Open nathanschwarz opened 4 years ago

nathanschwarz commented 4 years ago

Hi !

I would like to propose a change in the way the Plugin.registerCompiler works by letting it use multiple packages for the same extensions / filenames.

I know there's been some folks talking about this feature already, but none has really talked about pre-processing files (the most important feature to my eyes).

What do I mean by pre-processing files ?

Well, let's say you want to automate your style import flow.

you'll want to take all your jsx files and automatically import css files with the same name in the same directory without writting import "./filename.css" in each file manually.

By letting us writting a simple package that pre-process the jsx files and let us add this line programmatically would be convenient.

As you can see it's not "compilation" per say, but there's nothing on the Build pipeline that enables us to do such things now.

There's plenty of other examples like this that can't be done in Meteor unless you build a Plugin which transforms the code beforehand and then compile it (which requires a lot of time / knowledge).

The fact that you need to write a huge package (including compilation) to do such small things is kind of antipattern : the point of a package is to be modular and usable by the community.

Can it be done otherwise ?

At some extends (for simple cases) yes (with Babel for example), but it requires a lot of setup and it doesn't help the community. It's often external to Meteor environment which requires to "build around meteor" instead of building "with meteor".

What do I propose ?

add a boolean field isChainable in Plugin.registerCompiler config :

add a boolean field isCurrentlyInChain to InputFile enabling the next Plugin to override the file in the final map instead of using the source file.

add a config file .packages-config.json to enable the configuration of packages and set up the order of compilation to avoid conflicts.