I have packaged my Angular2 app with
npm run build:prod
Which compiles to the dist folder. 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.
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]/[bundled js file]
The problem is that these calls should be:
http://[server]/[app]/[bundled js file]
How do I fix this?
答案 0 :(得分:2)
IIS有两种选择。首先,只需将应用程序安装到IIS网站的根目录中(无应用程序directoy / virtual目录)。
如果您希望在IIS中使用应用程序或虚拟目录,则需要在webpack.dev.js中设置一个publicpath
output: {
path: helpers.root('dist'),
publicPath: '/SWP2/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
},
所以在上面的例子中我说webpack应该考虑它生成的引用存在于/ SWP2 /文件夹中,所以index.html会添加像
这样的引用<script type="text/javascript" src="/SWP2/vendor.628ff41b723fcc2315b1.js"></script><script type="text/javascript" src="/SWP2/app.628ff41b723fcc2315b1.js"></script>
当网址查找时,会使用http://localhost/SWP2/vendor.etcetc
保持dev配置为标准,否则你的代码不会解雇,除非在IIS中。