Closed
Description
I just use the whole vuejs-templates-webpack to create a project. I then installed bootstrap,in my entry js
i required the bootstrap less files with require('bootstrap/less/bootstrap.less');
,i then use the bootstrap glyphicon style class in my .vue
template, But when i run npm run build
, I found that the the fontface
in the vendorXXXXX.css
in the static/css
folder is ./static/fonts/glyphicons-halflings-regular.f4769f9.eot?#iefix
, therefore i got many 404 errors
when i visit the project from my server : rootpath/static/css/static/fonts
is not found on the server.
So, how to make vue-loader ignore resolving the path of the fontface in the bootstrap less file ?
Metadata
Metadata
Assignees
Labels
No labels
Activity
chrisvfritz commentedon Jun 20, 2016
This is a feature of css-loader. From their Usage docs:
url(image.png)
=>require("./image.png")
url(~module/image.png)
=>require("module/image.png")
Note the imoprtant
~
prefix to reference installed packages. Usingbootstrap-sass
in SCSS, this is what I use:aflext commentedon Jun 20, 2016
@chrisvfritz all my project uses less, its a huge work to transform to sass. And i don't think it's a good idea to modify the bootstrap source code.
yyx990803 commentedon Jun 20, 2016
Use plain
<link>
tag to include bootstrap. You don't need Webpack to process it anyway.chrisvfritz commentedon Jun 20, 2016
I wouldn't want to convert all my styles to a different language either. Fortunately, you don't have to. I use SCSS, so that's the example I had on hand, but a similar technique should work just as well for LESS. I do believe Bootstrap 4 will be SCSS-only, so that transition may be inevitable if you'd like to upgrade. 😞
As for modifying the Bootstrap source code - that's not what we're doing here. This isn't even a hack. These Bootstrap variables are made to be overridable. This is especially apparent in the SCSS version, where the variables all use
!default
, meaning that value should be assigned to the variable only if it hasn't been previously defined.aflext commentedon Jun 21, 2016
@yyx990803 Do you mean thant i just link the bootstrap.min.css file in the head of my html ? What if i want to use the less variables defined in bootstrap less ?
aflext commentedon Jun 21, 2016
@chrisvfritz Thanks a lot for replying, would you mind posting a demo code for using scss with variable override ?
chrisvfritz commentedon Jun 21, 2016
In that first example I provided, I'm overriding $icon-font-path by declaring it before the main Bootstrap import. In LESS, I believe variables are lazy-loaded, so you may have to declare that variable after the main Bootstrap import.
aflext commentedon Jun 21, 2016
@chrisvfritz I did try to override the font path variable in less with ,but the url path of font facc is still the like
./static/fonts/glyphicons-halflings-regular.448c34a.woff2
:src/home/Home.vue
:src/home/index.less
:dist/static/css/app.326961f0db864479a769a9efc95ceea9.css
:But i just want this
chrisvfritz commentedon Jun 22, 2016
Not sure, sorry. 😕 Haven't used the LESS version or LESS itself really. This issue on
css-loader
may have better information.LucienLee commentedon Nov 24, 2016
Actually, you could overwrite
publicPath
inExtractTextPlugin
as you want.This template extracts the styles when building and use the same public path as config. Hence, all path would default start like
/static/...
. In the original case, you got font face path asrootpath/static/css/static/fonts
, because you might change theassetsPublicPath
to relative path./
. In the stylesheet, your font face would like./static/fonts/...
, but css url would refer from the position of stylesheet. Then, you got this wrong onerootpath/static/css/static/fonts
.In this case, you could just add public path here.
If you still stick on webpack1, that would be like
return ExtractTextPlugin.extract('vue-style-loader', sourceLoader, {publicPath: '../../'})
bsqql123 commentedon May 11, 2017
I agree with @LucienLee ,but in webpack2,you can config app like this
docnoe commentedon May 11, 2017
@bsqql123 Thank you for that detailed description!
jiayouwyhit commentedon May 31, 2017
@bsqql123 @LucienLee Thank you so much for your detailed explanation. It really solves my issues.
11 remaining items