In an Angular2 application, I have a file loader setup in webpack config, like so:
{
test: /\.(eot|svg|ttf|woff|woff2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file?name=/assets/fonts/[name].[ext]'
}
I also have this elsewhere in the config:
modulesDirectories: ['node_modules']
As I understand, the file loader searches the node_modules folder for any files that match the expression given (in this case font files), and copies them over to the /assets/fonts
folder in the build output. However this does work, as no files actually get copied to to the destination folder. What am I missing?
On a side note, I also would like to know how conflicts are handled, as there could be files in node_modules
in multiple packages with the same name.
More information:
vendor.scss
file includes the following:
$zmdi-font-path: "assets/fonts";
@import "~material-design-iconic-font/scss/material-design-iconic-font.scss";
The sass-loader eventually applies this to result in the following css:
@font-face {
font-family: 'Material';
src:url('assets/fonts/Material-Design-Iconic-Font.woff2?v=2.2.0') format('woff2'),url('assets/fonts/Material-Design-Iconic-Font.woff?v=2.2.0') format('woff'),url('assets/fonts/Material-Design-Iconic-Font.ttf?v=2.2.0}') format('truetype');
font-weight: normal;
font-style: normal;
}
The two steps above will cause a request from the browser to the font file at assets/fonts/Material-Design-Iconic-Font.woff2?v=2.2.0
. This does not happen until runtime obviously. Where would I require
the file so that it is copied to assets/fonts at build time?
I am also using the sass-loader
in the pipeline:
{
test: /.scss$/,
loaders: ['raw-loader', 'sass-loader']
}
and include the sass in my component like this:
styleUrls: [
'./../assets/scss/main.scss'
]
I can see that the css is included in the HTML when seen from the browser, but calls to the fonts return 404.