Laravel + Elixir: importing bootstrap less error

2019-06-11 05:05发布

问题:

I've installed bootstrap with bower into /vendor/bower_components folder. Also I have an app.less file with this import:

@import '/vendor/bower_components/bootstrap/less/bootstrap';

For the time being it worked, when I run gulp I got public.css compiled and everything went good. However, I've reinstall npm/nvm/gulp/bower and such stuff and after then I got an error when running gulp:

[15:19:07] gulp-notify: [Laravel Elixir] Less Compilation Failed!: '/vendor/bower_components/bootstrap/less/bootstrap.less' wasn't found. Tried - /vendor/bower_components/bootstrap/less/bootstrap.less in file /var/www/rld/resources/assets/less/app.less line no. 1

Actually it works if I remove / (backslash) from the import path, but I don't quite understand what path should be used in my main app.less. It worked before but right now is broken, however on my another computer it works fine (not sure if I reinstall gulp what will happen). So I'm confused what path I should use for importing bootstrap less files.

回答1:

See also https://github.com/plus3network/gulp-less#options and then especially the paths option.

When you us the import path without the leading / (@import '/vendor/) the compiler will search relative from app.less (less/vendor). With a leading / it will try to find the file in the /vendor/ folder on your system (absolute path).



回答2:

You may change your app.less @import as follow:

@import "../../../vendor/bower_components/bootstrap/less/bootstrap";

Works for us