webpack-dev-server 配置proxy转发请求无效,麻烦大牛帮忙看下?
项目最近打包速度越来越慢,针对webpack进行了一些配置的优化,之前是用nginx + webpack -w来开发。但发现经过DllPlugin、happypack等配置webpack-dev-server的编译速度远远超过build速度。但是,也在最后一步卡主了,webpack-dev-server配置了proxy转发请求,但是无效。配置如下,麻烦哪位大牛帮我看一下,不胜感激~~
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var HappyPack = require("happypack");
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, './app/dci.js');
var BUILD_PATH = path.resolve(ROOT_PATH, 'dist');
var config = {
context: path.resolve(__dirname), // to automatically find tsconfig.json
devtool: false,
entry: [
'react-hot-loader/patch',
APP_PATH,
],
output: {
path: BUILD_PATH,
filename: "dci.js",
publicPath: "/",
chunkFilename: 'js/[id].[chunkhash].js',
},
//...
};
module.exports = config;
weback.dev.config.js
var config = require('./webpack.config.js');
var webpack = require('webpack');
var path = require('path');
var ROOT_PATH = path.resolve(__dirname);
var BULID_PATH = path.resolve(ROOT_PATH, '/dist/');
var HtmlWebpackPlugin = require('html-webpack-plugin');
config.devServer = {
port: 8018,
publicPath: "http://localhost/dist/", //我猜测可能是这里的问题,但是不知道怎么修改
host: '0.0.0.0',
hot: true,
inline: true,
// contentBase: BULID_PATH,//告诉服务器从哪里提供内容
historyApiFallback: true,
compress: true,
disableHostCheck: true,
proxy: {
'/api': {
target: 'http://192.168.200.55:8080', //这里并没有生效,依然是在8018端口发送的请求
secure: false,
changeOrigin: true
}
}
};
config.devtool = 'eval';
config.plugins.push(new webpack.DefinePlugin({
process: {
env: {
NODE_ENV: JSON.stringify('development')
},
noDeprecation: true
}
}));
config.plugins.push(
new webpack.NamedModulesPlugin()
);
config.plugins.push(
new webpack.HotModuleReplacementPlugin()
);
config.plugins.push(
new HtmlWebpackPlugin({
title: 'Hot Module Replacement',
template: path.join(__dirname, '/dist/dci.html')
})
);
module.exports = config;
求指点迷津
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看你访问的是 /dist/api,把配置里也改成这样试试,不知道你为什么要加/dist
你在浏览器上看到的肯定是8018端口的,不然你设置代理来意义何在
昨天从github与Stack Overflow上试了很多的配置还是不过,只好回头仔细研究webpack-dev-server文档几项描述。找到问题所在,下面贴出来:
webpack.config.js
proxy.publicPath
@YoungYou