【问题标题】:Webpack dev server live reload with proxyWebpack 开发服务器使用代理实时重新加载
【发布时间】:2017-04-15 15:25:02
【问题描述】:

我正在localhost:8000 运行PHP 应用程序。
我想使用webpack-dev-server 热重载cssreactjs 组件。
已将代理设置为 http://localhost:8000webpack-dev-server 没有重新加载浏览器。

这是webpack.config.js

var path = require( 'path' );
var autoprefixer = require( 'autoprefixer' );

module.exports = {
    entry: [
        './src/app.js'
    ],
    output: {
        path: path.join( __dirname, 'dist' ),
        publicPath: 'http://localhost:8000',
        filename: 'app.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loaders: [ 'react-hot', 'babel-loader' ]
            },
            {
                test: /\.scss$/,
                loaders: [ 'style-loader', 'css-loader', 'sass-loader' ]
            }
        ]
    },
    postcss: [
        autoprefixer(
            {
                browsers: [
                    'last 2 versions'
                ]
            }
        )
    ],
    devServer: {
        port: 3000,
        proxy: {
            '**': {
                target: 'http://localhost:8000',
                secure: false,
                changeOrigin: true
            }
        }
    }
}

我正在通过http://localhost:3000/webpack-dev-server/ 访问webpack-dev-server

更改我的react 组件确实会导致webpack-dev-server 重新编译,但浏览器不会更新。

运行webpack 会编译dist/app.js 文件,因为手动调用它并重新加载浏览器是可行的。

【问题讨论】:

    标签: proxy webpack webpack-dev-server


    【解决方案1】:

    所以我的publicPath 错了。
    这是修复:

    output: {
        path: path.join( __dirname, 'dist' ),
        publicPath: 'http://localhost:3000/dist/',
        filename: 'app.js'
    },
    

    更新:但是好像要重新加载浏览器¯_(ツ)_/¯

    【讨论】:

    • 你们都设法解决了这个问题吗?我也在尝试代理,更改后整个浏览器都会刷新,而不是在不刷新的情况下注入更改。我在客户端使用 webpack-dev-server 和 react-hot-reload,在服务器端使用节点服务器。
    • 我想我做到了。但已经有一段时间了。不记得我做了什么:)
    • 我知道感觉:) 如果你记得或有一些代码示例,请发布它。在整个互联网上似乎没有解决方案:)
    • 我无法再访问它了,因为我离开了。应该写博客。当你发现时,也许你可以写博客:)
    猜你喜欢
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 2017-06-07
    • 2018-12-02
    • 2020-01-29
    • 2019-05-11
    • 2017-11-03
    相关资源
    最近更新 更多