javascript - 用于 React 的 Webpack 不起作用

标签 javascript linux reactjs webpack

我刚刚开始 React,并完成了 codecademy 类(class)和 youtube 上的其他几门类(class)。我决定配置我的本地机器以进行 react 。我已经开始使用 webpack 和 webpack-dev-server。在这里我弄错了。 Here is mistake screenshot

Also Here is my files tree

这是我的 webpack.config.js:

var webpack = require('webpack');
var path = require('path');

module.exports = {
    devtool: 'inline-source-map',
    entry: [
        'webpack-dev-server/client?http://127.0.0.1:8080/',
        'webpack/hot/only-dev-server',
        './src'
    ],
    output: {
           path: path.join(__dirname, 'public'),
           filename: "bundle.js"
    },
    resolve: {
        modulesDirectories: ['node_modules', 'src'],
        extensions: ['', '.js']
    },
    module: {
        loader: [
        {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']
        }
        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ]
};

我的 index.html:

<!DOCTYPE html>
<html>
<head>
    <title>React ToDos App</title>
</head>
<body>
    <div id="app" />
    <script src="bundle.js"></script>
</body>
</html>

和 index.js:

let message = 'Hello from entry message';

console.log(message);

感谢您的帮助。

最佳答案

我在您的代码中发现了两个问题:

  1. js bundle 的名称在 html 和 webpack 中应该相同——您在 webpack 配置中使用 ready.js 并在 html 中使用 bundle.js。<
  2. 在您的屏幕截图中,您有一个错字,webpack 配置的名称是 webpack.congig.js,但它应该是 webpack.config.js(由默认为 webpack-dev-server)

关于javascript - 用于 React 的 Webpack 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40090321/

相关文章:

javascript - 在 react 类组件中使用不带参数的柯里化(Currying)函数的目的是什么?

Javascript链表

linux - 如果 dpkg 和 apt-get 都无法删除 Ubuntu 上的程序怎么办?

javascript - 如何将 props 发送到组件以响应条件?

javascript - React Native 如何监听生命周期中的上下文变化

javascript - react 原生导航 - child 不更新父更新

javascript - 考虑到过滤选项是可选的,过滤数组

linux - 是否有可能在两个或多个Linux系统之间建立硬链接(hard link)或软链接(soft link)?

python - 在 CentOS 6.7 上安装 python33 时出错

reactjs - 具有编辑模式和查看模式的 React 组件,这是正确的模式吗?