【问题标题】:Angular2 with webpack reports error 404 index.html not found带有 webpack 的 Angular2 报告错误 404 index.html not found
【发布时间】:2016-10-31 12:11:39
【问题描述】:

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

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

或

http://localhost:8080/index.html

它报告 404 index.html not found.

我不知道为什么。

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

【问题讨论】:

    标签: angular webpack webpack-dev-server


    【解决方案1】:

    由于你的项目已经拆分了你的 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'
        }
    });
    

    希望对你有帮助。

    【讨论】:

    • 这个建议解决了我的主要问题。配置修复后出现另一个问题 - 错误的加载程序“html”。当我将其更改为“原始”时,它开始工作。非常感谢!
    • 不客气,另一个可能对您有所帮助的建议是您的 package.json 文件中缺少您的 extract-text-webpack-plugin 依赖项,要运行您的应用程序,我必须放置此依赖项“ extract-text-webpack-plugin": "^1.0.1"
    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 2017-05-11
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多