我在webpack中遇到问题,我尝试使用ant设计...但是当应用程序运行时...出现如下错误,请帮助我谢谢。我曾尝试通过Google搜索但找不到正确的方法回答
此文件webpack.config.js
const path = require("path");
module.exports = {
entry: { main: "./src/index.js" },
mode: "development", // "production" | "development" | "none"
output: {
path: path.resolve(__dirname, "./wwwroot/dist"), // string
// the target directory for all output files
// must be an absolute path (use the Node.js path module)
filename: "bundle.js", // the filename template for entry chunks
publicPath: "dist/" // string // the url to the output directory resolved relative to the HTML page
},
resolve: {
extensions: [".js", ".jsx"]
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
plugins: ["react-hot-loader/babel"]
}
}
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader"
]
},
{
test: /\.(png|woff|woff2|eot|ttf|svg|jpg)$/,
loader: "url-loader?limit=100000"
}
]
}
};
此文件.babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
["import", { "libraryName": "antd"}],
"@babel/proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-syntax-dynamic-import",
[
"@babel/plugin-transform-runtime",
{
"corejs": false,
"helpers": true,
"regenerator": true,
"useESModules": false
}
]
]
}
此文件package.json
{
"name": "myapp",
"version": "1.0.0",
"description": "react + dotnet core + webpack + openidconnect",
"main": "app.js",
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "narbe hs",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"aspnet-webpack": "^3.0.0",
"aspnet-webpack-react": "^4.0.0",
"babel-loader": "^8.0.4",
"babel-plugin-transform-runtime": "^6.23.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"webpack": "^4.28.3",
"webpack-cli": "^3.1.2",
"webpack-dev-middleware": "^3.5.0",
"webpack-hot-middleware": "^2.24.3",
"style-loader": "^0.23.1",
"css-loader": "^2.1.0"
},
"dependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/runtime": "^7.2.0",
"antd": "^3.25.1",
"axios": "^0.19.0",
"babel-plugin-import": "^1.12.2",
"es6-promise": "^4.2.5",
"file-loader": "^4.2.0",
"formik": "^2.0.3",
"html-webpack-plugin": "^3.2.0",
"jwt-decode": "^2.2.0",
"node-sass": "^4.13.0",
"react-hot-loader": "^4.6.3",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"redux": "^4.0.0",
"redux-form": "^7.4.2",
"redux-thunk": "^2.3.0",
"sass": "^1.23.3",
"sass-loader": "^8.0.0",
"url-loader": "^2.2.0",
"yup": "^0.27.0"
}
}
如何解决以上图片错误?我的webpack有什么问题?
答案 0 :(得分:0)
看起来您的正则表达式/\.s[ac]ss$/i
仅捕获scss
和sass
扩展名。请看一下:https://webpack.js.org/guides/asset-management/#loading-css为CSS文件添加规则。如果要使用同一规则捕获scss,sass和css,请使用此/(\.css|\.scss|\.sass)$/