filemanager-webpack-plugin icon indicating copy to clipboard operation
filemanager-webpack-plugin copied to clipboard

replace in file

Open rszik opened this issue 5 years ago • 7 comments

Hi,

Could you please consider to implent a 'replace in file' action, that would be great.

Thanks :)

rszik avatar Dec 08 '19 18:12 rszik

Seconding this. I use ReplaceInFileWebpackPlugin today, but I can't get it to execute before the FileManagerPlugin starts

sebastientromp avatar Dec 07 '20 08:12 sebastientromp

Seconding this. I use ReplaceInFileWebpackPlugin today, but I can't get it to execute before the FileManagerPlugin starts

Saw the plugin, FMP uses afterEmit hook and ReplaceInFileWebpackPlugin used done hook. afterEmit executes before done hook. so it is not possible.

Also I am not so sure about replacing in file, since this happens before and after the compilation. Problem with that is If we are replacing the content of the emitted file after compilation, it will change the contenthash of the files, will then need to find and replace in all of its related assets.

sibiraj-s avatar Dec 07 '20 12:12 sibiraj-s

Thanks for the reply, I understand. Then it seems that there is no real solution if you want to zip the dist after changing some values in it.

Do you think it could be possible to add a wait timer, as a workaround? Or a kind of "beforeHook" that would let the user run some logic before executing the onEnd events (which in my case could let me tell the script to sleep for 1s for instance)

sebastientromp avatar Dec 07 '20 13:12 sebastientromp

Do you think it could be possible to add a wait timer, as a workaround? Or a kind of "beforeHook" that would let the user run some logic before executing the onEnd events (which in my case could let me tell the script to sleep for 1s for instance)

Not sure. can you post what you are trying to achieve?

Also I saw the processassets hook in webpack-5, about letting users specify the stage and callback with assets. I am not sure that will help. but I haven't got enough time to evaluate the options.

sibiraj-s avatar Dec 07 '20 15:12 sibiraj-s

I have a few config file in my app with placeholder values, and I use ReplaceInFileWebpackPlugin to replace these placeholders with their actual values.

Then I want to zip my whole dist folder. With the current timing of the operations though, the FileManager kicks in before the replace file process can complete, and so I still have the placeholders in my final zip.

So it's really an operation that I want to perform once the full build process is over.

sebastientromp avatar Dec 07 '20 16:12 sebastientromp

got it. may be if you are using webpack 5 you could use this plugin copy-asset-in-memory-webpack-plugin and tap into a specific stage to do the transform/replace on the code, or use copy-webpack-plugin which also has a transform function (I am not sure that will help your case) Meanwhile I'll see what I can do here.

sibiraj-s avatar Dec 08 '20 05:12 sibiraj-s

Could you add some additional compiler hooks such as onDone, afterDone etc? This should make it possible to attach the plugin to different phases and resolve the issue.

vparchas avatar Mar 23 '21 14:03 vparchas