简体   繁体   English

Angular2 WebPack部署到IIS中默认网站下的应用程序

[英]Angular2 WebPack Deploy to Application under Default Web Site in IIS

I have packaged my Angular2 app with 我已经将Angular2应用打包为

npm run build:prod npm运行build:prod

Which compiles to the dist folder. 编译到dist文件夹。 I've then taken the contents of this dist folder and placed it in an Application folder under the Default Web Site of my IIS Server. 然后,我获取了此dist文件夹的内容,并将其放在IIS服务器的“默认网站”下的“应用程序”文件夹中。

I then browse to http://[server]/[app] , and nothing seems to happen, but a view of the Network tab of the browser dev tools shows the index.html is loading, and that it is making calls to the bundled js files as follows: 然后,我浏览到http:// [server] / [app] ,似乎没有任何反应,但是浏览器开发工具的“网络”标签的视图显示index.html正在加载,并且正在调用捆绑的js文件如下:

http://[server]/[bundled js file] http:// [服务器] / [捆绑的 js文件]

The problem is that these calls should be: 问题在于这些调用应该是:

http://[server]/[app]/[bundled js file] http:// [服务器] / [应用] / [捆绑的 js文件]

How do I fix this? 我该如何解决?

You have two options for IIS. IIS有两个选项。 Firstly just install the app into the root of the IIS web site (no application directoy/virtual directory). 首先,只需将应用程序安装到IIS网站的根目录(无应用程序directoy / virtual目录)。

If you wish to use an application or virtual directory within IIS then you need to set a publicpath inside you webpack.dev.js 如果您希望在IIS中使用应用程序或虚拟目录,则需要在webpack.dev.js中设置一个publicpath

output: {
path: helpers.root('dist'),
publicPath: '/SWP2/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'

}, },

So in the above example I am saying that webpack should consider its generated references live in the /SWP2/ folder so the index.html will have added references like 因此,在上面的示例中,我说的是webpack应该将其生成的引用考虑在/ SWP2 /文件夹中,因此index.html将添加诸如

<script type="text/javascript" src="/SWP2/vendor.628ff41b723fcc2315b1.js"></script><script type="text/javascript" src="/SWP2/app.628ff41b723fcc2315b1.js"></script>

and when the URL looks for them it would use http://localhost/SWP2/vendor.etcetc 当URL查找它们时,它将使用http://localhost/SWP2/vendor.etcetc

Keep the dev config as standard as otherwise your code wont fire except when in IIS. 保持dev config为标准配置,否则除非在IIS中,否则您的代码不会触发。

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

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