下一个js HTML未加载到css中

5t7ly7z5  于 2023-01-18  发布在  其他
关注(0)|答案(1)|浏览(131)

我正在使用Nextjs并在_app. js中加载flaticon css,如:
import '../public/assets/css/flaticon.css';
在以下内容中,我遇到错误:

@font-face {
  font-family: 'Flaticon';
  src: url('../fonts/Flaticon.eot');
  src: url('../fonts/Flaticond41d.eot?#iefix') format('embedded-opentype'),
    url('../fonts/Flaticon.woff') format('woff'),
    url('../fonts/Flaticon.ttf') format('truetype'),
    url('../fonts/Flaticon.html#Flaticon') format('svg');
  font-weight: normal;
  font-style: normal;
}

我收到以下错误:

error - ./public/assets/css/Flaticon.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!DOCTYPE html>
| <html lang="en-US" prefix="og: http://ogp.me/ns#">
|   <head>
nafvub8i

nafvub8i1#

通过以下步骤解决此问题:
1.安装html加载程序
npm install --save-dev html-loader
1.将其添加到next.config.js文件中

webpack: (config, options) => {
    config.module.rules.push({
      test: /\.html$/i,
      use: 'html-loader',
    });

    return config
  }

参考:https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config

相关问题