Rails: missing node compiled asset modules

I use yarn with my rail 5.1 app (and not webpacker, just the default asset pipeline).

Running a local server in a development environment, I have no problems with my assets.

But as soon as I recompile my assets (the environment does not matter) or let Heroku pack my assets, all the stylesheets (from node modules) that I imported from my file application.sassno longer work.

The reason for this behavior is that sass compiles all the files into a single output file, but for some reason, it apparently skips the statements @importthat include the node modules and downloads these files separately.

So this is:

@import "components/index.sass"
@import "nodemodule/nodemodule.css"

This will compile during development:

// content of "components/index.sass"
// content of "nodemodule/nodemodule.css"

and to this in the production process:

// content of "components/index.sass"
@import "nodemodule/nodemodule.css"

node_module/nodemodule.css , . Javascript .

+8
3

- . sass-rails sprockets Rails.

1) sass-rails

@import, , node_modules, . , node_modules , , .

2) sprockets

Sprockets 'require , . , :

. , . , , Sprockets . "" , .

, application.sass.

+2

, asset.rb /node_modules /node_modules .

rails console Rails.application.config.assets.paths /yourproject/node_modules.

:

@import "nodemodule.css"

4 application.scss

@import bootstrap/scss/bootstrap

node_modules/bootstrap/scss/bootstrap.scss

enter image description here

jquery.js bootstrap.js application.js

+7

node_modules needs to be installed using npm install, for example, so they probably won't be installed on Heroku. Check out https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app

Most likely, you need to configure Node.js buildpack, which will install your npm dependencies.

+1
source

Source: https://habr.com/ru/post/1690195/


All Articles