0

Using CopyWebpackPlugin, I'm trying to copy a file with a specific version in the name (e.g. "calcitemaps-arcgis-support-v0.9.js", "otherlibaray-v0.9.js") to my output directory, but stripping the version ("-v0.9) from the filename.

Using the test and toType options, I would think that

{
   from: './node_modules/calcite-maps/dist/js/dojo/*0.9*',
   to: './calcite/[1].[ext]',
   toType: 'template',
   flatten: true,
   test: /(.*(?=-))\.js/
  }

should work, but all I'm getting in my destination directory is a file called [1].js.

I also tried /.*(?=-)\.js/, /(.*(?=-))/, and /.*(?=-)/, none of them worked...

RegEx is obviously not my strong suit here - can anyone help?

crackernutter
  • 203
  • 1
  • 3
  • 12
  • 1
    After hyphen `-` I see there is `v0.9` string as well. Try changing your regex to this `/(.*(?=-))-v0\.9\.js/` in case you want to only match files having `v0.9` before `.js` or if you want to match any version, generalize the version regex like this ``/(.*(?=-))-v\d+(\.\d+)*\.js/`` – Pushpesh Kumar Rajwanshi Feb 15 '19 at 15:39
  • The directory has all versions in it, and I want to target a specific version, based on an environment variable - so my from value is actually `./node_modules/calcite-maps/dist/js/dojo/*${process.env.VERSION_TO_TARGET}*`. But for some reason the expression you suggested just makes webpack hang and the build never finishes....is the idea in order to use templates, you need at minimum capture groups? – crackernutter Feb 15 '19 at 15:57
  • I don't think capture groups should be making it hang, but just in case it is, then you can make it a non-grouping pattern by appending `?:` before starting `(` and change your regex to `(?:.*(?=-))-v\d+(?:\.\d+)*\.js` – Pushpesh Kumar Rajwanshi Feb 15 '19 at 16:01
  • okay - your regex is working, but webpack is getting hung up on the template. Looking at the debug, it shows - `writing '../../../calcite/H:\www\eonearth\node_modules\calcite-maps\dist\js\dojo\calcitemaps.js' to compilation assets from 'H:\www\eonearth\node_modules\calcite-maps\dist\js\dojo\calcitemaps-v0.9.js'` - I can start a new thread to address this issue... – crackernutter Feb 15 '19 at 17:06
  • Sorry I've never used webpack tool, so not sure what is causing it to hang. But some googling for `webpack tool hangs` showed me decent results pointing to some other issues. [Check this](https://github.com/webpack/webpack/issues/8234) and [even this](https://stackoverflow.com/questions/39085686/webpack-hangs-at-on-95-emit-95-emitting) May be try googling a bit and it might give you some helpful pointers. – Pushpesh Kumar Rajwanshi Feb 15 '19 at 17:23

0 Answers0