Rails Premailer Webpacker Using Full Paths
I've ran into this a couple of times and it's taken forever to figure out! I don't know how I fixed it before, but this is how I fixed it this time.
I've ran into this a couple of times and it's taken forever to figure out! I don't know how I fixed it before, but this is how I fixed it this time.
The Problem
When using premailer-rails with webpacker, I run into this error:
ArgumentError: not an HTTP URI
After some digging I found the issue is with the premailer-rails
gem. It's trying to
request the stylesheet using a full path; file://....
. This path is coming from the webpack
manifest file. I'm not sure why it's using a full path, but it is.
The Solution
const { webpackConfig, merge } = require('shakapacker')
const customConfig = {
output: {
publicPath: process.env["RAILS_ENV"] === "test" ? "/packs-test/" : webpackConfig.output.publicPath,
}
}
module.exports = merge(webpackConfig, customConfig)
This forces webapck to use a relative path instead of a full path.
Webmentions
These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: