简体   繁体   English

gulp webpack-dev-server更改未应用

[英]gulp webpack-dev-server changes not applied

Trying to set up webpack-dev-server using gulp. 尝试使用gulp设置webpack-dev-server。 When a change occurs, webpack-dev-server appears to rebuild the bundle.js file, but if I refresh the page, it'd be still the same. 发生更改时,似乎会使用webpack-dev-server来重建bundle.js文件,但是如果刷新页面,则该页面仍然相同。 I have to manually compile the bundle.js with webpack, and restart the server every time. 我必须使用webpack手动编译bundle.js,然后每次重新启动服务器。

gulpfile.js gulpfile.js

gulp.task('webpack-dev-server', function() {
    var compiler = webpack(require('./webpack.config'));
    new WebpackDevServer(compiler, {
        contentBase: 'public',
        historyApiFallback: true,
        progress: true,
        inline: true
    }).listen(8000, 'localhost', (err) => {
                if(err) throw new $.util.PluginError('webpack-dev-server', err);
                $.util.log('[webpack-dev-server]', 'http://localhost:8000');
    });
});

webpack.config.js webpack.config.js

module.exports = {
    entry: [
        './src/index.js'
    ],
    output: {
        path: __dirname + '/public/js',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.(jsx|js)$/,
                loader: "babel-loader",
                exclude: /node_modules/,
                query: {
                    presets: ["es2015", "react"]
                }
            }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    devServer: {
        contentBase: 'public',
        inline: true,
        progress: true
    }
};

Found the problem: contentBase was using the disk's root as the project's root instead of the project folder itself. 发现了问题:contentBase使用磁盘的根作为项目的根,而不是项目文件夹本身。 So the path became "F:\\public". 因此路径变为“ F:\\ public”。 I changed it to contentBase: __dirname + 'public' and it works. 我将其更改为contentBase: __dirname + 'public'并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM