带有 webpack 的 Angular2 报告错误 404 index.html not found

Angular2 with webpack reports error 404 index.html not found

我使用 Angular2 启动了一个项目,但是当我打开时

http://localhost:8080/webpack-dev-server/index.html 

http://localhost:8080/index.html

它报告 404 index.html 未找到。

我不知道为什么。

我正在使用 Windows。 The project is available on Github.

由于你的项目已经拆分了你的webpack配置,它需要合并这些配置以便webpack理解你的所有参数。

最简单的方法是使用 lodash 中的 _.merge 方法,查看更多信息:https://lodash.com/docs/4.16.4#merge

首先安装 lodash 依赖项:

npm install --save-dev lodash

然后你合并你的配置,你的 webpack.config.js 应该看起来像:

var path = require('path');
var webpack = require('webpack');
var helpers = require('./helpers');
var _ = require('lodash');

var commonConfig = require('./webpack.common.js');

module.exports = _.merge(commonConfig, {
    devtool: 'cheap-module-eval-source-map', // source-map
    output: {
        path: helpers.root('dist'),
        //publicPath: '/',
        filename: '[name].js',
        chunkFilename: '[id].chunk.js',
    },
    devServer: {
        historyApiFallback: true,
        stats: 'minimal'
    }
});

希望对您有所帮助。