I'm trying to import some font (like Roboto) in my project using webpack but none of them works.
My file structure looks like this:
+-src---fonts-+-Roboto---Roboto.ttf
| |
| +-fonts.css
|
+-webpack.config.js
My fonts.css
file:
@font-face {
font-family: 'Roboto';
src: url(/Roboto/Roboto.ttf) format('truetype');
}
My webpack.config.js
looks like this:
//...
loaders: [
{
test: /\.css/,
loaders: [
'style-loader',
`css-loader?${JSON.stringify({
sourceMap: isDebug,
localIdentName: isDebug ? '[name]_[local]_[hash:base64:3]' : '[hash:base64:4]',
modules: true,
minimize: !isDebug,
importLoaders: 1
})}`,
'postcss-loader',
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
loader: 'url-loader',
},
{
test: /\.(wav|mp3|eot|ttf)$/,
loader: 'file-loader',
},
],
//...
When i run webpack, no error shows up. But the Roboto
font was not loaded (texts are still of default font-family, though i've set font-family: 'Roboto'
to the text element).
What I've tried:
Change the paths in
.css
files'url()
s to relative path: errors came out:ERROR in ./~/css-loader?{"sourceMap":true,"localIdentName":[name][local][hash:base64:3]","modules":true,"minimize":false,"importLoaders": 1}!./~/postcss-loader!./fonts/fonts.css Module not found: Error: Cannot resolve module 'Roboto/Roboto.ttf' in /Users/EnixCoda/projectName/fonts @ ./~/css-loader?{"sourceMap":true,"localIdentName":"[name][local][hash:base64:3]","modules":true,"minimize":false,"importLoaders":1}!./~/postcss-loader!./fonts/fonts.css 6:135-163
Could anyone help me?