How do I use environment variables inside webpacker.yml?
Tried this syntax and it takes it as a literal string
<%= ENV['x'] %>
@ratneshraval Webpacker.yml doesn't support erb since we use the same file on both JS and Ruby side. What's your use case?
I want to set webpacker public_output_path based on rails RAILS_RELATIVE_URL_ROOT
Ahh right, this is in todo but for now I guess you can append RAILS_RELATIVE_URL_ROOT in environment.js.
const { config, environment } = require('@rails/webpacker')
const ManifestPlugin = require('webpack-manifest-plugin')
const outputPath = `${config.outputPath}/${process.env.RAILS_RELATIVE_URL_ROOT}`
const publicPath = `${process.env.RAILS_RELATIVE_URL_ROOT}${config.publicPath}`
environment.plugins.append('Manifest', new ManifestPlugin({ publicPath, writeToFileEmit: true }))
environment.config.merge({
output: {
publicPath,
path: outputPath
}
})
module.exports = environment
I tried that with command
RAILS_RELATIVE_URL_ROOT=/xyz bundle exec rails assets:precompile
but it didn't work! The packs were still placed directly in public/packs instead of public/xyz/packs
@ratneshraval Updated example ^^
Will get this in next release 馃憤
Lets track this issue in #1357
Most helpful comment
I want to set webpacker
public_output_pathbased on railsRAILS_RELATIVE_URL_ROOT