2017-02-16 69 views
1

相對路徑我有一個簡單的組件工作正常:角2條的WebPack

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    templateUrl: `./src/app/app.component.html`, 
    styleUrls: ['./src/app/app.component.css'] 
}) 
export class AppComponent { } 

的問題是路徑是絕對的。我改成了這樣:

@Component({ 
    selector: 'my-app', 
    templateUrl: `./app.component.html`, 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { } 

,它給我一個錯誤:

GET http://localhost:7000/app.component.html 404 (Not Found)

的問題是我怎麼可以使用相對路徑用的WebPack(的moduleId:module.id這裏不工作),而不第三部分裝載機或東西,如:使用的WebPack 2.2.1本裝載機

template: require('...') 

由我真的方式:

module: { 
     rules: [ 
      { 
       test: /\.js/, 
       include: srcPath, 
       exclude: /node_modules/, 
       loader: 'babel-loader', 
       query: { 
        presets: ['es2015', { "modules": false }], 
        cacheDirectory: true, 
        optional: 'runtime' 
       } 
      }, 
      { 
       test: /\.tsx?$/, 
       loader: 'awesome-typescript-loader', 
       exclude: /node_modules/ 
      }, 
      { 
       test: /\.html$/, 
       use: 'raw-loader' 
      }, 
      { 
       test: /\.css$/, 
       use: ['style-loader', 'css-loader'] 
      } 
     ] 
    }, 
+0

您是否能夠使用角度2模板加載程序計算出此值?我想知道你是否將'templateUrl'改爲'template'並且不得不刪除'./' – Winnemucca

+1

我使用的模板是這樣的:templateUrl:'main.component.html'用於同一個文件中的文件。 –

回答