curiouscode
curiouscode

Reputation: 409

Remove /assets directory completely from Rails 6 app

I'm setting up a new Rails 6 app and moved all of my assets over to webpack. I now want to delete my empty app/assets directory, but doing so means Rails won't boot because Sprockets can't find my missing manifest.js file:

> Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)
But did not, please create this file and use it to link any assets that need
to be rendered by your app:

Example:
  //= link_tree ../images
  //= link_directory ../javascripts .js
  //= link_directory ../stylesheets .css
and restart your server

I haven't found any good solutions for completely removing Sprockets. Creating an empty assets directory just to hold a manifest file I'm no longer using doesn't seem like the optimal solution here. Yes, it will work, but what's the point of moving to webpack if Rails still forces us to use Sprockets and have a JS manifest file?

Has anyone successfully removed their assets directory completely? Thanks for your help!

Upvotes: 2

Views: 1974

Answers (1)

Ilham Adi
Ilham Adi

Reputation: 21

I just removed app/assets from my apps, getting similar error. Solve by:

  1. Change this line in config/application.rb

from

require 'rails/all'

to

require 'rails'
# Pick only the frameworks we want:
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
require 'active_storage/engine'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_mailbox/engine'
require 'action_text/engine'
require 'action_view/railtie'
require 'action_cable/engine'
# require "sprockets/railtie"
require 'rails/test_unit/railtie'
  1. Remove all config.assets.* in config/environments/*
  2. Delete config/initializers/assets.rb

Upvotes: 2

Related Questions