Webpack热重装通过gulp,publicPath导致问题

时间:2015-09-02 03:00:26

标签: webpack webpack-dev-server

我似乎无法让热重载功能正常工作。每当我进行更新时,都会收到以下错误消息:

获取http://localhost:9090/cd0492f7657672ef15e4.hot-update.json 404(未找到)
[HMR]无法应用更新。需要完全重装!
[HMR](可能是因为重新启动了webpack-dev-server)

我很确定这是由publicPath: '/js/',中的gulpfile.js引起的,因为当我去http://localhost:9090/cd0492f7657672ef15e4.hot-update.json时我得到了404 {但是当我去http://localhost:9090/js/cd0492f7657672ef15e4.hot-update.json时,我可以找到文件。

publicPath: '/js/'需要app.js,所以我不知道如何修复它,任何想法?

webpack.config.js

var webpack = require('webpack');
module.exports = {
    cache: true,
    entry: ['webpack/hot/dev-server', './resources/assets/app.js'],
    output: {
        path: __dirname + '/public/js',
        publicPath: '/js/',
        filename: "scripts.js"
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel'
            }
        ]
    }
};

gulpfile.js

...
var webpackConfig = require('./webpack.config.js');
...
gulp.task('webpack-dev-server', function(callback) {
    // modify some webpack config options
    var myConfig = Object.create(webpackConfig);
    myConfig.devtool = 'eval';
    myConfig.debug = true;
    myConfig.plugins = [
        new webpack.HotModuleReplacementPlugin()
    ];

    // Start a webpack-dev-server
    new webpackDevServer(webpack(myConfig), {
        hot: true,
        stats: {
            colors: true
        },
        publicPath: '/js/',
        proxy: {
            '*': 'http://localhost:8080'
        }
    }).listen(9090, 'localhost', function(err) {
        if (err) throw new gulpUtil.PluginError('webpack-dev-server', err);
    });
});

0 个答案:

没有答案