Deploy Angular 2 App with Webpack to Tomcat - 404 Errors

前端 未结 6 939
暖寄归人
暖寄归人 2020-12-01 14:50

I want to build and deploy my Angular 2 front end to a Tomcat application server. For getting started I\'ve followed exactly the steps of the following introduction: https:/

6条回答
  •  旧时难觅i
    2020-12-01 15:33

    The problem is related to the tag . This is just wrong when using a webserver like tomcat or trying to load the app directly from filesystem with firefox index.html. This must be changed to . When the app still has problems check how the script files are imported. I tried to use angular2-webpack with tomcat and also needed to change all script tags to not use a leading slash in there src attribute.

    
    

    With webpack the behavior is controlled by the attribute output.publicPath. In the angular2 documentation and in the angular2-webpack this is set to

    output.publicPath="/"
    

    Which leads to absolute path in the links. When removed webpack will use relative paths and the links for scripts and images work.

提交回复
热议问题