首页 > 解决方案 > 无法运行反应项目

问题描述

我是 reactjs 的新手。我正在尝试编写 webpack。

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './main.js',
output: {
  path: path.join(__dirname, '/bundle'),
  filename: 'index_bundle.js'
},
devServer: {
  inline: true,
  port: 3000
},
module: {
  rules: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     },
     {
        test: /\.scss$/,
        use: [{
            loader: "style-loader"
        }, {
            loader: "css-loader"
        }, {
            loader: "sass-loader",
            options: {
                includePaths: ["absolute/path/a", "absolute/path/b"]
            }
        }]
     }
  ]
  },
  plugins:[
  new HtmlWebpackPlugin({
     template: './index.html'
  })
 ]
 }

Html Webpack插件:错误:子编译失败:找不到入口模块:错误:无法解析'F:\ react-app'中的'F:\ react-app \ index.html':错误:无法解析' F:\react-app\index.html' in 'F:\react-app'

标签: reactjswebpack.config.js

解决方案


plugins:[
  new HtmlWebpackPlugin({
     hash:'true'
     template: './index.html'
  })
 ]

将 hash 设置为 true 并确保您拥有正确的模板文件位置。


推荐阅读