在和我的网络包进行了一场史诗般的战斗之后,我需要去睡觉了。老实说,我不知道问题出在哪里。
我尝试了几个小时,从网上复制了一些webpack配置。
这是我的webpack.config文件
const path = require('path');
const MiniCssExtractPlugin = require('css-minimizer-webpack-plugin');
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
module.exports = {
entry: './src/index.tsx',
module: {
rules: [
{
test: /\.json$/,
use: 'json-loader',
},
{
test: /\.(js)x?$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(ts)x?$/,
exclude: /node_modules|\.d\.ts$/,
use: {
loader: 'ts-loader',
options: {
compilerOptions: {
noEmit: false,
},
},
},
},
{
test: /\.(scss|css)$/,
// exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'style-loader' },
{ loader: 'css-loader' },
// This is needed to help find the KaTeX fonts.
// https://github.com/bholloway/resolve-url-loader/issues/107
// https://github.com/bholloway/resolve-url-loader/issues/212
// https://stackoverflow.com/questions/54042335/webpack-and-fonts-with-relative-paths
// https://stackoverflow.com/questions/68366936/how-to-bundle-katex-css-from-node-modules-to-a-single-output-css-from-a-sass-us
'resolve-url-loader',
{
loader: "sass-loader",
options: {
// This is needed for resolve-url-loader to work!
// https://github.com/bholloway/resolve-url-loader/issues/212#issuecomment-1011630220
sourceMap: true,
sassOptions: {
includePaths: [nodeModulesPath],
},
},
},
],
},
],
},
plugins : [new MiniCssExtractPlugin()],
resolve : {
extensions: ['.css', '.tsx', '.ts', '.js'],
},
output : {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
}
};
我收到错误消息:
["..." | object { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }, ...]
-> A rule.
Details:
* configuration.module.rules[3].use[0] should be one of these:
object { ident?, loader?, options? } | function | non-empty string
-> A description of an applied loader.
Details:
* configuration.module.rules[3].use[0] should be an object:
object { ident?, loader?, options? }
* configuration.module.rules[3].use[0] should be an instance of function.
* configuration.module.rules[3].use[0] should be a non-empty string.
-> A loader request.
* configuration.module.rules[3].use[0] should be one of these:
object { ident?, loader?, options? } | function | non-empty string
-> An use item.
Error: Process completed with exit code 2.
然而,我想要的只是导入Katex,就像
import 'katex/dist/katex.min.css'
到我的表组件中。
也许有人有办法?
1条答案
按热度按时间ktecyv1j1#
好吧,我找到了。正因为我很难在网上找到正确的答案(可能只有我这么想)--这就是我的解决方案。
我想在typescript React中使用katex-在这里显示一个漂亮的表https://0xpolygonmiden.github.io/examples/。
为此,我将其导入到了表组件中
所以Katex有自己的CSS文件。在本地它运行良好,渲染漂亮。但是,当我试图在GitHub页面上部署时,Webpack兼容该导入缺少一个
loader
。好的。所以我试着为webpack 5的导入找到正确的加载程序。
这只是
sass-loader
和默认情况下node-modules
被排除在外,所以我不得不删除exclude: /node_modules/,
当我定义的sass-loader
的CSS文件.容易,哈?这里是完整的代码,对于那些谁有兴趣.
https://github.com/0xPolygonMiden/examples/tree/main/playground