Here's my working setup with a Tailwind plugin (tw-elements), Rails 7, importmaps -- notably using NO nodejs, package.json, esbuild/webpack, etc.
After running:
bin/importmap pin --download tw-elements
bin/importmap pin --download tw-elements/dist/plugin.cjs
I have in my config/importmap.rb
:
pin "tw-elements", to: "tw-elements.js", preload: true # @1.1.0
pin "tw-elements/dist/plugin.cjs", to: "tw-elements--dist--plugin.cjs.js" # @1.1.0
I reference these from config/tailwind.config.js
thus:
module.exports = {
content: [
'./public/*.html',
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/views/**/*.{erb,haml,html,slim}',
'./vendor/javascript/tw-elements.js', // TW-ELEMENTS //
],
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
require('../vendor/javascript/tw-elements--dist--plugin.cjs.js'), // TW-ELEMENTS //
],
}
Note the ../
is required in one place, but forbidden in the other! That's because when we call require
in the plugins
section our working dir is RAILS_ROOT/config
, but in content
the paths are relative to RAILS_ROOT
.
Behavior may vary slightly for different plugins, but this should provide a solid foundation.