Skip to content

Importing 3rd party css files from the node_modules folder #92

Closed
@GregSmith92

Description

@GregSmith92

I am moving from webpack to esbuild with jsbundling-rails & cssbundling-rails.
In a vendor directory I have a file which imports css files required by some JS packages like so:

@import "drift-zoom/dist/drift-basic.min.css";
@import "dropzone/dist/min/dropzone.min.css";
@import "select2/dist/css/select2.css";
@import "slick-slider/slick/slick.scss";
@import "slick-slider/slick/slick-theme.scss";

This file is then imported in my application.sass.scss.

In the logs I get a series of errors for each file like:
ActionController::RoutingError (No route matches [GET] "/assets/select2/dist/css/select2.css"):

It seems the problem may be that it is looking in app/assets for these files, when they are at the root under node_modules instead.

In config/initializers/assets I have Rails.application.config.assets.paths << Rails.root.join('node_modules')

A similar issue was posted to the jsbundling-rails page (which I think should of been here), where OP added additional paths to config.assets, like so: Rails.application.config.assets.paths << Rails.root.join("node_modules/photoswipe/src/css/default-skin"), but this has not worked for me.

The scripts I have in my package.json are:

"scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",
    "build:css": "sass ./app/assets/stylesheets/application.sass.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"

EDITS:
I have noticed that only the css files fail to be found, the scss files work fine. Maybe coincidence, I am usnure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions