执行纱线启动时接收无法GET /

时间:2019-12-10 15:10:09

标签: javascript reactjs webpack yarn webpack-dev-server

我是React和Yarn的新手,并遵循了有关如何使用Yarn和WebPack设置React应用程序的指南。 指南:https://levelup.gitconnected.com/react-webpack-babel-b76545c6e353

我想更改webpack.config.js以便在运行bundle.js时将yarn build文件写到根文件夹之外。但是这样做会使yarn start中断,而我在浏览器中收到Cannot GET /。我已将问题跟踪到path: __dirname + './../someFolder/someOtherFolder/这一行,如果我将其删除,则yarn start将不再显示错误。

知道我能做什么吗?我想在开发时继续在根文件夹之外进行构建。这是我的webpack.config.js

var HtmlWebpackPlugin = require('html-webpack-plugin');

const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
    template: './src/index.html',
    filename: './index.html'
})

module.exports = {
    module: {
        rules: [
            {
                test: /\.js|jsx$/,
                exclude: /node_modules/,
                use: { loader: 'babel-loader' }
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }
        ]
    },
    mode: 'development',
    devServer: {
        historyApiFallback: true,
        compress: true,
        port: 3030,
        open: true
    },
    plugins: [
        HtmlWebpackPluginConfig
    ],
    entry: './src/index.js',
    output: {
        filename: 'pw_module.js',
        path: __dirname + './../someFolder/someOtherFolder/',
        publicPath: '/'
    }
};

这是我的"scripts":中的package.json部分:

  "scripts": {
    "start": "webpack-dev-server --hot",
    "lint": "eslint ./src",
    "test": "jest --colors -b -e --logHeapUsage",
    "build": "webpack --mode production"
  }

0 个答案:

没有答案