【问题标题】:Error 404 bundle.js not found - Spring Data Rest and React.js找不到错误 404 bundle.js - Spring Data Rest 和 React.js
【发布时间】:2018-10-12 22:58:04
【问题描述】:

我想用Spring构建应用并做出反应,所以我开始学习这个教程:https://github.com/spring-guides/tut-react-and-spring-data-rest/tree/master/basic

我的项目包含相同的文件 - 我是一步一步完成的(刚刚分享了我的项目以寻求帮助 https://github.com/Lewan110/rest-react)。 Spring Data rest 运行良好,因为我得到了正确的数据,但是当我转到 http://localhost:8080 时,我没有得到任何数据,并且 bundle.js 出现错误

这对我来说很奇怪,因为 bundle.js 是在以下位置生成的:\src\main\resources\static\built\bundle.js webpack.config.js 看起来也不错:

var path = require('path');

module.exports = {
    entry: './src/main/js/app.js',
    devtool: 'sourcemaps',
    cache: true,
    debug: true,
    output: {
        path: __dirname,
        filename: './src/main/resources/static/built/bundle.js'
    },
    module: {
        loaders: [
            {
                test: path.join(__dirname, '.'),
                exclude: /(node_modules)/,
                loader: 'babel',
                query: {
                    cacheDirectory: true,
                    presets: ['es2015', 'react']
                }
            }
        ]
    }
};

我是 React(和 JS)的新手,我不知道原因在哪里。

【问题讨论】:

    标签: javascript spring reactjs spring-boot


    【解决方案1】:

    bundle.js 文件应该在public 文件夹中而不是在src 文件夹中(如果你想在开发服务器中使用bundle.js,这当然没有意义)。

    当您构建一个用于生产的 React 应用程序时,它可以直接在您选择的服务器中使用。因此,当您处于开发阶段时,您在完成工作之前不会构建您的 React 应用程序.

    顺便说一句,生成的应用程序不应位于您的 src 文件夹中,而应位于 publicsrc 文件夹所在的同一文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 2019-07-14
      • 2017-10-18
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      相关资源
      最近更新 更多