反应关键字扩展不接
react keyword extends doesnt pick up
我已经尝试学习 webpack 一段时间了,它似乎没有图像问题或 css...只是反应,我收到以下错误消息。它不认识它...
我已经尝试阅读和修复它很长时间了,所以,如果我不是新手,任何帮助将不胜感激,我们将合作帮助他人。
在我的 React 页面中
const img = require('./dog.jpeg');
require('./style.css');
import React from 'react';
import ReactDOM from 'react-dom';
class Page extends React.Component () {
render(){
return(
<div>
<p>A silly complicated way to show an HTML document</p>
</div>
);
}
}
在我的 webpack.common.js 文件中
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry:{
app: './src/index.js',
},
plugins : [
new CleanWebpackPlugin(['../dist']),
new HtmlWebpackPlugin({
title: 'Web w react, express webpack dev n prod',
})
],
output : {
filename: '[name].bundle.js',
path: path.resolve(__dirname, '../dist')
},
module : {
rules:[
// {
// test: /\.js$/,
// loader: 'babel-loader',
// exclude: /node_modules/,
// query: {presets: ['es2015']}
// },
{
test: /\.(jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react']
}
}
},
// {
// test: /\.jsx$/,
// loader:'babel-loader',
// query: {presets: ['es2015', 'react']}
// },
{
test:/\.(css|scss)$/,
use:['style-loader', 'css-loader','sass-loader']
},
{
test: /\.(png|jpeg|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
fallback: 'file-loader'
}
}
]
}
]
}
}
error message that comes up
所有代码都在这个link
Link to this on Github
查看您的模块加载器规则。唯一会远程文件加载 js 文件的规则在这里:
{
test: /\.(jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react']
}
}
},
现在看test: /\.(jsx)$/
。这让 webpack 知道要使用对象中定义的给定配置加载哪些文件。您提到的错误文件是 .js
文件。如果你想让它加载相同的配置,你需要将 test
修改为 test: /\.(js|jsx)$/,
。所以它应该是这样的。
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react']
}
}
},
我还没有深入研究这个问题...所以请 lmk 如果这能解决您的问题。祝你好运!
我已经尝试学习 webpack 一段时间了,它似乎没有图像问题或 css...只是反应,我收到以下错误消息。它不认识它... 我已经尝试阅读和修复它很长时间了,所以,如果我不是新手,任何帮助将不胜感激,我们将合作帮助他人。
在我的 React 页面中
const img = require('./dog.jpeg');
require('./style.css');
import React from 'react';
import ReactDOM from 'react-dom';
class Page extends React.Component () {
render(){
return(
<div>
<p>A silly complicated way to show an HTML document</p>
</div>
);
}
}
在我的 webpack.common.js 文件中
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry:{
app: './src/index.js',
},
plugins : [
new CleanWebpackPlugin(['../dist']),
new HtmlWebpackPlugin({
title: 'Web w react, express webpack dev n prod',
})
],
output : {
filename: '[name].bundle.js',
path: path.resolve(__dirname, '../dist')
},
module : {
rules:[
// {
// test: /\.js$/,
// loader: 'babel-loader',
// exclude: /node_modules/,
// query: {presets: ['es2015']}
// },
{
test: /\.(jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react']
}
}
},
// {
// test: /\.jsx$/,
// loader:'babel-loader',
// query: {presets: ['es2015', 'react']}
// },
{
test:/\.(css|scss)$/,
use:['style-loader', 'css-loader','sass-loader']
},
{
test: /\.(png|jpeg|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
fallback: 'file-loader'
}
}
]
}
]
}
}
error message that comes up 所有代码都在这个link Link to this on Github
查看您的模块加载器规则。唯一会远程文件加载 js 文件的规则在这里:
{
test: /\.(jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react']
}
}
},
现在看test: /\.(jsx)$/
。这让 webpack 知道要使用对象中定义的给定配置加载哪些文件。您提到的错误文件是 .js
文件。如果你想让它加载相同的配置,你需要将 test
修改为 test: /\.(js|jsx)$/,
。所以它应该是这样的。
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react']
}
}
},
我还没有深入研究这个问题...所以请 lmk 如果这能解决您的问题。祝你好运!