webpack:new css-loader 4.0.0尝试加载字体(使它们嵌入);如何禁用此功能?

gfttwv5a  于 12个月前  发布在  Webpack
关注(0)|答案(2)|浏览(221)

在我的样式中,我有这样的字体定义:

@font-face {
    font-family: 'Material Icons';
    font-style: normal;
    font-weight: 400;
    src: local('Material Icons'), local('MaterialIcons-Regular'), 
        url(/fonts/MaterialIcons-Regular.woff2) format('woff2'), 
        url(/fonts/MaterialIcons-Regular.woff) format('woff'), 
        url(/fonts/MaterialIcons-Regular.ttf) format('truetype');
}

字符串
在我将css-loader更新到新版本4.0.0(几天前发布)后,我得到了这些错误(building bundle):
./src/index.scss模块生成失败(从./node_modules/css-loader/dist/cjs.js):错误:无法解析'D:\cot\EDelivery\EDelivery.Injected.AspCore.RegWebApp\src'中的'/fonts/MaterialIcons-Regular. woff 2' at doResolve(D:\cot\EDelivery\EDelivery\EDelivery.Injected.AspCore.RegWebApp\node_modules\enhanced-resolve\lib\Resolver.js:209:21)at hook.callAsync(D:\cot\EDelivery\EDelivery\EDelivery.Injected.AspCore.RegWebApp\node_modules\enhanced-resolve\lib\Resolver.js:285:5)at _fn0(eval at create(D:\cot\EDelivery\EDelivery\EDelivery.Injected.AspCore.RegWebApp\node_modules\tapable\lib\HookCodeFactory.js:32:10),:15:1)
在新版本中,css-loader似乎试图使字体嵌入。如何禁用此行为?(无法找到该选项:https://webpack.js.org/loaders/css-loader/
我的配置是:

{
        test: /\.(scss|css)$/,
        use: [
            MiniCssExtractPlugin.loader,
            {
                loader: "css-loader",
                options: {
                    sourceMap: true
                }
            },
            { // ... postcss-loader, sass-loader

ac1kyiln

ac1kyiln1#

而不是loader:“css-loader”,你可以像这样传递额外的参数来禁用该功能。"css-loader?url=false"

fae0ux8s

fae0ux8s2#

url: false选项添加到css和scss加载器

module: {
rules: [
  {
    test: /\.scss$/i,
    use: [
      {
        loader: "css-loader",
        options: {
          // Do not parse paths specified in url() and image-set to not include fonts to build
          url: false
        },
      },
      'sass-loader'
    ],
  },
],
},

字符串

相关问题