I have a completely clean project utilizing vue-templates/pwa
. Everything is working as intended. The SCSS files are loaded, but the paths for the fonts are failing.
The error message:
assets/fonts/DIN/din_alternate_bold_1-webfont.ttf in ./~/css-loader?{"minimize":false,"sourceMap":false}!./~/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-0312694b","scoped":true,"hasInlineConfig":false}!./~/sass-loader/lib/loader.js?{"includePaths":["./src/assets/scss"],"data":"@import /"base.scss/";","sourceMap":false}!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/TestLib.vue, ./~/css-loader?{"minimize":false,"sourceMap":false}!./~/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-242c44c2","scoped":false,"hasInlineConfig":false}!./~/sass-loader/lib/loader.js?{"includePaths":["./src/assets/scss"],"data":"@import /"base.scss/";","sourceMap":false}!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/TestLib/Tile.vue and 3 others
Some code and hierarchy:
/src
/assets
/fonts
/DIN
din_alternate_bold_1-webfont.ttf
/scss
/base
_typography.scss
base.scss
base.scss
@import 'base/typography'
_typography.scss
$font_path: '~assets/fonts/';
@font-face {
font-family: "DinAltBold";
src: url($font_path + "DIN/din_alternate_bold_1-webfont.ttf");
}
build/utils.js
exports.cssLoaders = function (options) {
options = options || {}
var cssLoader = {
loader: 'css-loader',
options: {
minimize: process.env.NODE_ENV === 'production',
sourceMap: options.sourceMap
}
}
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
var loaders = [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass', {
includePaths: ['./src/assets/scss'],
data: '@import "base.scss";'
}),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
Don't use tilde ~
for the relative path. This points to the node_modules
folder. So you have to options:
- Use
$font_path: '../../fonts/';
as mentioned from @highFlyingSmurfs or- Use
$font_path: '~/src/assets/fonts/';
where~/
points to the project root.
I got this information from the sass-loader GitHub Page which the Vue CLI
uses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With