You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
It is not clear to me how webpack knows that the path of the files inside the vendor array in the entry section is located in the local node_modules folder (this is another question that I would be grateful if you also answer :) )
So if I add this to the entry section, should I be pointing it to the correct path (to whatever folder I put the .ttf/.woff2 files)?
Or I should not use webpack for this and just reference it in my app.component.css like this below?
The idea with Webpack is that it auto-discovers the dependencies between files in your project, and hence automatically includes all the files that you will need at runtime.
For example, in CSS files, you can directly reference a font file (e.g., .ttf or .woff2), and then Webpack will automatically bundle up your font file according to whatever loader rule you have for .ttf/.woff2 files.
Your CSS code could look like this:
@font-face{src:local('Open Sans Light'),url(some-node-module/dir/some-font-file.ttf)format('woff2');/* ... other properties here ... */}
And then Webpack will look for node_modules/some-node-module/dir/some-font-file.ttf and includes it in your bundles. You don't have to mention some-font-file.ttf directly in your Webpack config.
Likewise, if you wanted to load the .ttf file from a path relative to your CSS file (e.g., not from node_modules), you could do so like this:
@font-face{src:local('Open Sans Light'), url(./some-font-file.ttf) format('woff2');/* ... other properties here ... */}
... and now it will look for some-font-file.ttf in the same directory as the CSS file that references it.
I see you already have url-loader configured for font files. With your config, font files under 100KB will be inlined into your CSS as base64 data URLs, whereas font files over 100KB will be outputted as separate files that are loaded at runtime via separate HTTP requests. That's a perfectly reasonable config.
So in summary, you don't have to do either of the things you mentioned (explicitly mention the font in your entry config, nor load it from a CDN). You can just let Webpack do the work for you :)
It is not clear to me how webpack knows that the path of the files inside the vendor array in the entry section is located in the local node_modules folder (this is another question that I would be grateful if you also answer :) )
Webpack resolves the file references like this:
For relative paths (e.g., ./some-file.extension or ../../dir1/dir2/some-file.extension), it resolves it relative to the file making that reference. Relative paths are ones that start with ./ or ../.
For non-relative paths (e.g., something/some-file.extension), it assumes the first segment is the name of an NPM module, and anything after that is a path inside the NPM module. For example, the path might be node_modules/something/some-file.extension within your project.
Activity
SteveSandersonMS commentedon Dec 8, 2016
The idea with Webpack is that it auto-discovers the dependencies between files in your project, and hence automatically includes all the files that you will need at runtime.
For example, in CSS files, you can directly reference a font file (e.g.,
.ttfor.woff2), and then Webpack will automatically bundle up your font file according to whatever loader rule you have for.ttf/.woff2files.Your CSS code could look like this:
And then Webpack will look for
node_modules/some-node-module/dir/some-font-file.ttfand includes it in your bundles. You don't have to mentionsome-font-file.ttfdirectly in your Webpack config.Likewise, if you wanted to load the
.ttffile from a path relative to your CSS file (e.g., not fromnode_modules), you could do so like this:... and now it will look for
some-font-file.ttfin the same directory as the CSS file that references it.I see you already have
url-loaderconfigured for font files. With your config, font files under 100KB will be inlined into your CSS as base64 data URLs, whereas font files over 100KB will be outputted as separate files that are loaded at runtime via separate HTTP requests. That's a perfectly reasonable config.So in summary, you don't have to do either of the things you mentioned (explicitly mention the font in your
entryconfig, nor load it from a CDN). You can just let Webpack do the work for you :)Webpack resolves the file references like this:
./some-file.extensionor../../dir1/dir2/some-file.extension), it resolves it relative to the file making that reference. Relative paths are ones that start with./or../.something/some-file.extension), it assumes the first segment is the name of an NPM module, and anything after that is a path inside the NPM module. For example, the path might benode_modules/something/some-file.extensionwithin your project.Hope that covers it!