0

I have a TypeScript/React web app that uses ParcelJS and I would like to have either a step in the build or a simple way of using a resource file that holds git information.

Not sure if there is something that can generate the git information during the build, I'm using npm to launch parcel.

If parcel can load a resource file and make it accessible that could also work by having properties.

My end goal would be to display version and git commit point in the webapp.

Sergio
  • 590
  • 1
  • 9
  • 16

1 Answers1

0

I'm going to assume you're using parcel2 (I'm not sure this would be possible in parcel1).

Parcel2 uses babel to transpile typescript by default (through the @parcel/transformer-babel plugin). The babel configuration for this plugin can be over-ridden by simply including a .babelrc (for configuration relevant to only a subset of the project) or babel.config.json file (for configuration that will apply to the entire project). See this scenario matrix that I made in the process of fixing this bug for details about exactly what babel config files should be picked up by parcel. (The "proposed fixes" are merged into parcel2 as of the latest nightly release).

With the ability to supply your own babel configuration, you should be able to use this babel plugin to inject git repository information into your code.

(Since you're using typescript, you'll also need to make sure to include @babel/preset-typescript or @babel/plugin-transform-typescript in your babel config as well).

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26