Laravel + Elixir: importing bootstrap less error

2019-06-11 05:04发布

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.

2条回答
戒情不戒烟
2楼-- · 2019-06-11 05:07

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).

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-06-11 05:23

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

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

Works for us

查看更多
登录 后发表回答