0

I'm the author of a library and I need a script to be run each time before webpack bundles my library into the user's app code.

My library's package.json would be something like this:

{
  "name": "some-js-library",
  "version": "0.1.0",
  "scripts": {
    "prebuild": "./path/to/my-libs-prebuild-script.js"
  }
}

The user's package.json could be anything, for example:

{
  "scripts": {
    "//": "or however the user uses webpack",
    "build": "webpack"
  },
  "dependencies": {
    "some-js-library": "^0.1.0"
  }
}

I don't have any control over my users' package.json, so I'm left to wonder if it's possible to have my-libs-prebuild-script.js executed every time before webpack starts building?

Ideally this would be a standard that every bundler agrees on, but a webpack only solution would be fine.

Thanks!

brillout
  • 7,804
  • 11
  • 72
  • 84
  • I don't think there's a supported way to modify the users Webpack configuration from an external library, with good reason. What specifically does your prebuild script do? – robinsax Sep 15 '20 at 19:45
  • it runs `git shortlog` to check how many Git authors the user's repo has. My library needs this information. When my library is consumed in a Node.js context that's not a problem. But when it used on the browser-side then I need to pass that info from build-time to runtime. – brillout Sep 15 '20 at 20:09

0 Answers0