简体   繁体   English

我在安装 webpack 时遇到问题

[英]I have problem with install webpack react

this is error这是错误

'React' is defined but never used

this is file app.js这是文件 app.js

import React from 'react';

this file webpack.config.js这个文件 webpack.config.js

const path = require("path");
module.exports = {
  context: __dirname,
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "main.js",
    publicPath: "/",
  },
  devServer: {
    historyApiFallback: true,
  },
  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: /node_module/,
        use: "babel-loader",
      },
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.(png|j?g|svg|gif)?$/,
        use: "file-loader",
      },
    ],
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: path.resolve(__dirname, "public/index.html"),
      filename: "index.html",
    }),
  ],
};

this is link that i learned https://medium.com/@imranhsayed/set-up-react-app-with-webpack-webpack-dev-server-and-babel-from-scratch-df398174446d这是我学到的链接https://medium.com/@imranhsayed/set-up-react-app-with-webpack-webpack-dev-server-and-babel-from-scratch-df398174446d

i have problem in step7, i istalled npm install eslint-plugin-react --save-dev but can't solve this problem.我在第 7 步有问题,我安装了 npm install eslint-plugin-react --save-dev 但无法解决这个问题。

Just to clarify, is this the entirety of your app.js file?澄清一下,这是您的 app.js 文件的全部内容吗?

import React from 'react';

Or have you also written the rest of the app.js file as laid out in step 7 of your link?或者您是否还编写了链接第 7 步中列出的 app.js 文件的 rest?

The error message you're seeing indicates that you have imported a module (React) but that you have yet to use it for anything.您看到的错误消息表明您已经导入了一个模块 (React),但您还没有将它用于任何事情。 If import React from 'react';如果import React from 'react'; is the entire contents of your app.js file, then this is to be expected;是您的 app.js 文件的全部内容,那么这是可以预料的; as you finish writing the app.js file, this error message will go away.当您完成编写 app.js 文件时,此错误消息将 go 消失。

You took a road that requires quite a lot of manualy work.你走了一条需要大量手工工作的道路。 For a beginner and even experienced users I strongly recommend the well known CRA tool ( create-react-app ).对于初学者甚至有经验的用户,我强烈推荐著名的 CRA 工具 ( create-react-app )。 It takes care to set up everything for you, including Babel and Webpack.它会为您设置一切,包括 Babel 和 Webpack。 Of course this depends on the actual React project, but I found that an excellent start.当然,这取决于实际的 React 项目,但我发现这是一个很好的开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM