markshapiro / webpack-merge-and-include-globally

Merge multiple files (js, css..) and include by running them "as is". Supports minify by custom transform and wildcard paths.
MIT License
102 stars 27 forks source link

Get filename in transform callback #58

Open ayush000 opened 3 years ago

ayush000 commented 3 years ago

Is it possible to get file path of the input file being transformed inside transform callback? For my use case, I need to pass the path to babel's transformSync method.

new MergeIntoSingleFilePlugin({
  files: {
   "output.js": ["inputFile1", "inputFile2", "inputFile3"]
  },
  transform: {
    // Filepath is currently not passed to transform callback. This is just an example to demonstrate use case
    "output.js": (code, filePath) => {
      babel.transformSync(code, {filename: filePath});
    }
  }
})

For now, it is working for me just by specifying some random filePath, since babel is just using filePath for matching it against overrides. But I was wondering if others might have a similar usecase.