Vue Cli Webpack代理

时间:2016-07-13 18:45:53

标签: proxy npm webpack vue.js webpack-dev-server

我一直在使用vue-cli和Webpack模板进行开发。一切都运作完美,但我在使用自定义主机时遇到了一些问题。现在Webpack监听localhost:8080(或类似),我希望能够使用自定义域,如http://project.dev。有人想出来了吗?

这可能是问题所在的地方: https://github.com/chimurai/http-proxy-middleware

我还将其添加到proxyTable: proxyTable: { 'localhost:8080' : 'http://host.dev' }它给了我一个控制台响应[HPM] Proxy Created / -> http://host.dev

任何建议,方向或建议都会很棒!

更新

我以这种方式成功地为我的Webppack项目添加了一个代理:

var mProxy = proxyMiddleware('/', {
   target: 'http://something.dev',
   changeOrigin: true,
   logLevel: 'debug'
}) 
app.use(mProxy)

这似乎有效,但仍不在80端口。

控制台日志: [HPM] Proxy created: / -> http://something.dev

我可以假设代理工作正常!但是当我访问网址时,我的资产没有被加载。

重要的是要注意我曾经使用Mamp - 并使用端口80.因此,我可以运行此代理的唯一方法是关闭Mamp并将端口设置为80.它似乎工作,但是当我用代理URL重新加载页面时 - 有一点延迟,试图解决,然后控制台输出这个:

[HPM] GET / -> http://mmm-vue-ktest.dev
[HPM] PROXY ERROR: ECONNRESET. something.dev -> http://something.dev/

这将显示在浏览器中: Error occured while trying to proxy to: mmm-vue-ktest.dev/

1 个答案:

答案 0 :(得分:0)

代理表用于将请求转发到另一台服务器,如开发API服务器。

如果您希望webpack dev服务器在此地址上运行,则必须将其添加到操作系统的<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@android:color/white"> <android.support.v4.widget.NestedScrollView android:id="@+id/frag_itemdetail_scrl_nested" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="fill_vertical" android:fillViewport="true" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <ExpandableListView android:id="@+id/frag_itemdetail_explist" android:layout_width="match_parent" android:layout_height="match_parent" android:transcriptMode="disabled" android:groupIndicator="@null"/> </android.support.v4.widget.NestedScrollView> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="@dimen/dimen_194"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsingtoolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:contentScrim="@android:color/white" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/frag_itemdetail_iv_itemimage" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/instantt" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.7"> </ImageView> <ProgressBar android:id="@+id/frag_itemdetail_prg_itemimage" android:layout_width="50dp" android:layout_height="50dp" android:layout_centerInParent="true"/> </RelativeLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?actionBarSize" app:layout_collapseMode="pin"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 文件中。 Vue或我们打包不能这样做,这是你的操作系统的工作。

Google将为每个操作系统提供简单的指南。