Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace in file #65

Open
rszik opened this issue Dec 8, 2019 · 7 comments
Open

replace in file #65

rszik opened this issue Dec 8, 2019 · 7 comments

Comments

@rszik
Copy link

rszik commented Dec 8, 2019

Hi,

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

Thanks :)

@sebastientromp
Copy link

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

@sibiraj-s
Copy link
Collaborator

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.

@sebastientromp
Copy link

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)

@sibiraj-s
Copy link
Collaborator

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.

@sebastientromp
Copy link

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.

@sibiraj-s
Copy link
Collaborator

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.

@vparchas
Copy link

vparchas commented Mar 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants