gpt4 book ai didi

css - 未找到模块 : Error: Can't resolve './@fortawesome/fontawesome-free/css/fontawesome.css'

转载 作者:行者123 更新时间:2023-12-04 15:58:30 27 4
gpt4 key购买 nike

我正在尝试使用 Font Awesome 5.1.0 在 webpack 4.
webpack配置文件的内容:

const HtmlWebPackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const autoprefixer = require('autoprefixer');

module.exports = {
entry: ["./src/index.js", "./src/index.scss", "react-hot-loader/patch"],
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.[hash].js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"]
}
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader",
options: {
minimize: true
}
}
]
},
{
test: /\.(sass|scss)$/,
use: [
{
loader: "file-loader",
options: {
name: "bundle.css"
}
},
{ loader: "extract-loader" },
{
loader: "css-loader"
},
{
loader: "postcss-loader",
options: {
plugins: () => [autoprefixer({ grid: false })]
}
},
{
loader: "sass-loader",
options: {
includePaths: ["./node_modules"]
}
}
]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name][hash].[ext]",
outputPath: "fonts/"
}
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html"
}),
new CopyWebpackPlugin([
{
from: "public"
}
])
]
};

在 index.scss 文件中:
@import "@fortawesome/fontawesome-free/css/fontawesome.css";
@import "@material/button/mdc-button.scss";
@import "@material/drawer/mdc-drawer.scss";
@import "@material/top-app-bar/mdc-top-app-bar.scss";
@import "@material/list/mdc-list.scss";
@import "./App/scss/app.scss";


* {
padding: 0;
margin: 0;
}

html, body {
height: 100%;
width: 100%;
}

#root {
display: flex;
flex-direction: row;
box-sizing: border-box;
height: 100%;
width: 100%;
}

正如你可以在图片上:

enter image description here

Font-awesome 是从正确的地方导入的,但我遇到了编译器错误:
ERROR in ./src/index.scss
Module not found: Error: Can't resolve './@fortawesome/fontawesome-free/css/fontawesome.css' in '/home/developer/Desktop/reasonreact/cockpit/src'
@ ./src/index.scss
@ multi (webpack)-dev-server/client?http://localhost:9000 webpack/hot/dev-server ./src/index.js ./src/index.scss react-hot-loader/patch

我究竟做错了什么?

更新

我将 webconfig 更改为:
  {
test: /\.(sass|scss)$/,
use: [
{
loader: "file-loader",
options: {
name: "bundle.css"
}
},
{ loader: "extract-loader" },
{
loader: "css-loader"
},
{
loader: "postcss-loader",
options: {
plugins: () => [autoprefixer({ grid: false })]
}
},
{
loader: "sass-loader",
options: {
includePaths: ["./node_modules", "src", "."]
}
}
]
},

我有以下错误:
ERROR in ./src/index.scss
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) ReferenceError: require is not defined
at runLoaders (/home/developer/Desktop/reason-react/cockpit/node_modules/webpack/lib/NormalModule.js:300:13)
at /home/developer/Desktop/reason-react/cockpit/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /home/developer/Desktop/reason-react/cockpit/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at context.callback (/home/developer/Desktop/reason-react/cockpit/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at process._tickCallback (internal/process/next_tick.js:68:7)
@ multi (webpack)-dev-server/client?http://localhost:9000 webpack/hot/dev-server ./src/index.js ./src/index.scss react-hot-loader/patch

最佳答案

有点晚了,但也许它可以帮助某人:
我认为而不是

@import "@fortawesome/fontawesome-free/css/fontawesome.css";
它应该是
@import '~@fortawesome/fontawesome-free/css/fontawesome.css';

关于css - 未找到模块 : Error: Can't resolve './@fortawesome/fontawesome-free/css/fontawesome.css' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com