Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在Web包开发服务器中找不到bundle.js_Reactjs_Webpack_Webpack Dev Server - Fatal编程技术网

Reactjs 在Web包开发服务器中找不到bundle.js

Reactjs 在Web包开发服务器中找不到bundle.js,reactjs,webpack,webpack-dev-server,Reactjs,Webpack,Webpack Dev Server,我对React/Redux/Webpack/Router有问题 任何“子页面”,如:“/主页/测试”、“用户/注册”等。。。未能加载-加载webpack生成的“bundle.js”文件时出错 原因似乎是获取“bundle.js”的请求具有以下url: 对于路径“/home/test”:“/home/bundle.js” 对于路径“/users/registration”:“/users/bundle.js” 加载“css”文件和其他资源时也会出现同样的问题 这是我的网页包配置: cons

我对React/Redux/Webpack/Router有问题

任何“子页面”,如:“/主页/测试”、“用户/注册”等。。。未能加载-加载webpack生成的“bundle.js”文件时出错

原因似乎是获取“bundle.js”的请求具有以下url:

对于路径“/home/test”:“/home/bundle.js” 对于路径“/users/registration”:“/users/bundle.js”

加载“css”文件和其他资源时也会出现同样的问题

这是我的网页包配置:

    const { resolve } = require('path');

const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');

const config = {
  devtool: 'cheap-module-eval-source-map',

  entry: [
    'react-hot-loader/patch',
    'webpack-dev-server/client?http://localhost:8080',
    'webpack/hot/only-dev-server',
    './main.js',
    //'./assets/scss/main.scss',
  ],

  output: {
    filename: 'bundle.js',
    path: resolve(__dirname, 'dist'),
    publicPath: '/',
  },

  context: resolve(__dirname, 'src'),

  devServer: {
    hot: true,
    contentBase: resolve(__dirname, 'build'),
    publicPath: '/',
    historyApiFallback: true
  },

  module: {
    rules: [
      /* {
        enforce: "pre",
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: "eslint-loader"
      }, */
      {
        test: /\.(js|jsx)$/,
        loaders: [
          'babel-loader',
        ],
        exclude: /node_modules/,
      },
      {
        test: /\.(scss|sass)$/,
        exclude: /node_modules/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            {
              loader: 'sass-loader',
              query: {
                sourceMap: false,
              },
            },
          ],
          publicPath: '../'
        }),
      },
      { test: /\.(png|jpg|gif)$/, use: 'url-loader?limit=15000&name=images/[name].[ext]' },
      { test: /\.eot(\?v=\d+.\d+.\d+)?$/, use: 'file-loader?&name=fonts/[name].[ext]' },
      { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&mimetype=application/font-woff&name=fonts/[name].[ext]' },
      { test: /\.[ot]tf(\?v=\d+.\d+.\d+)?$/, use: 'url-loader?limit=10000&mimetype=application/octet-stream&name=fonts/[name].[ext]' },
      { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: 'url-loader?limit=10000&mimetype=image/svg+xml&name=images/[name].[ext]' },
    ]
  },

  plugins: [
    new webpack.LoaderOptionsPlugin({
      test: /\.js$/,
      options: {
        eslint: {
          configFile: resolve(__dirname, '.eslintrc'),
          cache: false,
        }
      },
    }),
    new webpack.optimize.ModuleConcatenationPlugin(),
    new ExtractTextPlugin({ filename: './styles/style.css', disable: true, allChunks: true }),
    new CopyWebpackPlugin([{ from: 'vendors', to: 'vendors' }]),
    new OpenBrowserPlugin({ url: 'http://localhost:8080' }),
    new webpack.HotModuleReplacementPlugin(),
  ],
};

module.exports = config;
似乎出于某种原因,它总是使用“./bundle.js”来查找它

任何帮助都将不胜感激:)


谢谢,

检查帮助我是否尝试了不同的建议,但仍然无法使其发挥作用-我将尝试寻找其他样板文件,并提供一个确切的示例,然后从那里回溯。。。不管怎样,谢谢你的帮助我尝试了不同的建议,但仍然无法使其发挥作用-我将尝试寻找其他的样板文件,其中有一个确切的例子,然后从那里回溯。。。无论如何谢谢你