javascript - 404 因为重启 webpack-dev-server

标签 javascript django webpack webpack-dev-server

当我尝试更改我的 react 组件并保存它以查看热加载器是否更新了我的页面时,我在我的开发人员工具中得到了这个:

GET http://localhost:3000/public/bundle/76566a1ad7e45b834d4e.hot-update.json 404 (Not Found)hotDownloadManifest @ main.js:26hotCheck @ main.js:210check @ main.js:9288(anonymous function) @ main.js:9346
main.js:9303 [HMR] Cannot find update. Need to do a full reload!
main.js:9304 [HMR] (Probably because of restarting the webpack-dev-server)

我不确定为什么会这样。我正在尝试将 django 作为我的后端服务器运行 ( webpack instructions )

这是我的 webpack.watch.js:

var path = require('path');
var config = require("./webpack.config.js");
var Webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");

var port = process.env.WEBPACK_PORT || 3000;
var host = process.env.HOST || 'localhost';

config.entry.unshift(
    "webpack-dev-server/client?http://" + host + ":" + port,
    "webpack/hot/only-dev-server"   // only prevents reload on syntax errors
);

config.plugins = [
    new Webpack.HotModuleReplacementPlugin(),
    new Webpack.NoErrorsPlugin(), // don't reload if there is an error
    new ExtractTextPlugin("style.css", {
        allChunks: true
    })
];

config.module.loaders = [
    { test: /\.css$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') },
    { test: /\.json$/, loader: 'json-loader' },
    { test: /\.jsx$/, loaders: ['react-hot', 'babel-loader'], include: path.join(__dirname, 'app') },
    { test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
    { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
    { test: /\.scss$/, exclude: /node_modules/, loaders: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader') }
];

config.devServer = {
    publicPath:  config.output.publicPath,
    filename: 'main.js',
    contentBase: './public',
    hot:         true,
    // Make connection between webpack-dev-server and its runtime set inline: true
    inline:      true,
    lazy:        false,
    quiet:       true,
    noInfo:      true,
    headers:     {"Access-Control-Allow-Origin": "*"},
    stats:       {colors: true},

    // webpack-dev-server will serve built/bundled static files from host:port
    host:        "0.0.0.0",
    port:        port
};

module.exports = config;

这是我的 webpack.config.js:

module.exports = {
    entry: [
        './app/index.js'
    ],

    output: {
        path: './public/bundle',
        filename: 'main.js',
        publicPath: 'http://localhost:3000/public/bundle/'
    },

    plugins: [
        new BundleTracker({filename: './webpack-stats.json'}),
    ],

    module: {
        loaders: [
            { test: /\.css$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') },
            { test: /\.json$/, loader: 'json-loader' },
            { test: /\.jsx$/, loaders: ['react-hot', 'babel-loader'], include: path.join(__dirname, 'app') },
            { test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
            { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
            { test: /\.scss$/, exclude: /node_modules/, loaders: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader') }
        ]
    },
}

最佳答案

而不是使用

entry: [
    './app/index.js'
],

作为你的条目

像这样添加两个额外的条目:

entry: [
    'webpack-dev-server/client?http://localhost:3000', // WebpackDevServer host and port
    'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors
    './app/index.js' // Your appʼs entry point
]

关于javascript - 404 因为重启 webpack-dev-server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33328898/

相关文章:

javascript - 有没有一种简洁的方法可以在同一函数中更改多个 div 的innerHTML?

javascript - super 菜单转换为移动下拉菜单

sql - 用于慢速 SQL 查询的 Django 日志过滤器

javascript - 如何通过 ES6 + Webpack 在浏览器中使用我的 Javascript 库?

Vue.js 构建并部署到单个文件

javascript - Chart JS 无法在 iOS 设备上呈现

javascript - 如何从网站播放 PLS 文件?

django - 原子事务不起作用 django rest

python - 在 Django 中,如何在运行 syncdb 时从 SQL 文件创建表

jquery - 将 Webpack 用于简单站点