Webpack 网页第5页错误“;未捕获错误:模块分析失败:意外字符'@'&引用;加载字体时
添加到后,使用此节点模块时出现生成错误 这是我的Webpack 网页第5页错误“;未捕获错误:模块分析失败:意外字符'@'&引用;加载字体时,webpack,sass,font-face,webfonts,sass-loader,Webpack,Sass,Font Face,Webfonts,Sass Loader,添加到后,使用此节点模块时出现生成错误 这是我的 模块:{ 规则:[ { 测试:/\.tsx?$/,, 使用:“巴别塔加载器”, 排除:/node_模块/, }, { 测试:/\.s[ac]ss$/i, 用法:[“样式加载器”、“css加载器”、“sass加载器”], }, { 测试:/\(png | svg | jpg | jpeg | gif)$/i, 类型:“资产/资源”, }, { 测试:/\(woff | woff2 | eot | ttf | otf)$/i, 类型:“资产/资源”,
模块:{
规则:[
{
测试:/\.tsx?$/,,
使用:“巴别塔加载器”,
排除:/node_模块/,
},
{
测试:/\.s[ac]ss$/i,
用法:[“样式加载器”、“css加载器”、“sass加载器”],
},
{
测试:/\(png | svg | jpg | jpeg | gif)$/i,
类型:“资产/资源”,
},
{
测试:/\(woff | woff2 | eot | ttf | otf)$/i,
类型:“资产/资源”,
},
],
},
如果我像这样从配置中删除sass加载程序
,构建就会成功(但是我不能在我的项目中使用sass文件)
{
测试:/\.css$/i,
使用:[“样式加载器”、“css加载器”],
},
我做错了什么?我在本地玩了你的repo,似乎你的
css
文件没有被任何加载程序覆盖。我只添加了以下内容,就按预期运行了构建:
{
test: /\.css$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
如果你玩弄这些规则,你应该能够:
- 优化加载程序,使css文件不会通过sass加载程序运行
- 改进通用测试正则表达式,使其覆盖所有cass/scss/css文件
index.CSS
。我正在将其导入我的typescript index.tsx文件:这是正确的正则表达式,可以同时包含sass和CSS/\(scss | CSS)$/I
。我只是从文档中复制了正则表达式,没有考虑它。谢谢
Uncaught Error: Module parse failed: Unexpected character '@' (2: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
| /* roboto-cyrillic-ext-400-normal*/
> @font-face {
| font-family: 'Roboto';
| font-style: normal;
at eval (index.css:1)
at Object../node_modules/@fontsource/roboto/index.css (index.js:18)
at __webpack_require__ (index.js:556)
at fn (index.js:767)
at eval (index.tsx:6)
at Module../src/index.tsx (index.js:62)
at __webpack_require__ (index.js:556)
at index.js:1613
at index.js:1617
{
test: /\.css$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},