Reputation: 906
With .env files, it was easy to inject variables in webpacker js packs. Since 5.2, you can use the encrypted secrets, but is there a way to read (decrypt) them in inject some of them on webpacker build time?
Upvotes: 6
Views: 1039
Reputation: 5270
You can read from credentials and pass that value to Webpacker.
Create a config/initializers/webpacker.rb
file.
Pass it to the Webpacker::Compiler
through file above.
Webpacker::Compiler.env['VALUE'] = Rails.application.credentials.dig(:value)
Read it as console.log(process.env.VALUE)
.
If you want to try it on development
, you need to add these to the bin/webpack-dev-server
:
require_relative '../config/application'
Rails.application.initialize!
Sources:
Upvotes: 10