Angular2/Webpack: how to load fonts that are imported inside css files?

核能气质少年 提交于 2019-12-05 21:09:41

When you chain multiple loaders together, the order of their actions are completed from right to left.

Then the resulting code from the loader is passed to the next one. In this case, you want to chain the raw-loader and url-loader like this to give you the desired result:

loaders: ['raw-loader', 'url-loader']

Since you need to first have your font urls, automatically converted to base64 encoded in the styles, you must first call url-loader in your chain. Then since you are looking to import this file as a module.exports, you call raw-loader.

So in the chain the following happens:

  1. url-loader: Converts all of your url references to static assets into base64:data.
  2. raw-loader: Takes your file, and wraps its entire code with a string and then makes it importable by adding module.exports='string'
        Just Try once to keep under one dir both font and css

        // and give the reference onces in webpack.config.rb

         # Set this to the root of your project when deployed:
         http_path = "/"
         css_dir = "app/assets/css"
         sass_dir = "app/assets/sass"

try this:

@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
styles: [
  require('../stylesheets/css/main.min.css').toString(),
  require('!style-loader!css-loader!less-loader!../less/example.less').toString()
]})

I khow the commanand for less, similar command should be available for scss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!