Angular2 Typescript app throws 404 on components when js extension not specified

前端 未结 7 1431
青春惊慌失措
青春惊慌失措 2021-02-12 09:32

I just started to play around with Angular2, and ran into a weird component file extension problem:

Let\'s use the 5 minutes quickstart demo from angular.io (I\'ll repro

7条回答
  •  梦如初夏
    2021-02-12 10:29

    You can configure the path to your app folder. In my case, I'm using angular 2 to produce a mobile version of our app and had to configure System like so:

    System.config({
                paths: {
                    'app/*': './js/mobile/dist/*'
                },
                packages: {        
                  app: {
                    format: 'register',
                    defaultExtension: 'js'
                  }
                }
              });
              System.import('app/main')
                    .then(null, console.error.bind(console));
    

    As you can see, I decided to map "app" to "dist" where I have my compiled js files to keep them separate from the ts files.

提交回复
热议问题