angular2 / webpack模板404错误

时间:2016-09-24 01:42:32

标签: node.js angular webpack webpack-dev-server

我遵循了本教程,得到了与教程一样的内容。 https://www.youtube.com/watch?v=4i1nLrqMR14#t=563.837081

现在是时候扩展我的应用程序了,所以我为我的组件创建了一个html文件,并将我的templatURL设置为templateUrl: './app.html',因为它位于root / app / app.html所在的目录中。我收到错误,因为它正在root / app.html上查找。请参阅项目结构和错误的附件。

开发人员更改跟踪命令:

webpack-dev-server --inline --progress --port 4000 --content-base src

enter image description here

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
     "types": [
       "core-js",
       "node"
     ]
  },
  "exclude": [
    "node_modules"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useWebpackText": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": { "rewriteTsconfig": false }
}

webpack.config.js

var webpack = require('webpack');
var HtmlWebPackPlugin = require('html-webpack-plugin');
var path = require('path');

module.exports = {
    //entry:'./src/main.ts',
    entry:{
        'polyfills':'./src/polyfills.browser.ts',
        'vendor': './src/vendor.browser.ts',
        'main': './src/main.ts',
    },
    output:{
        path:'./dist',
        //filename:'app.bundle.js'
        filename: '[name].bundle.js',
        sourceMapFilename: '[name].map',
        chunkFilename: '[id].chunk.js'


    },
    module:{
        loaders:[{test:/\.ts$/, loader:'ts-loader'}]
    },
    resolve:{
         root: [ path.join(__dirname, 'src') ], //add this for dev server
        extensions:['','.js','.ts']
    },
    plugins:[

        //inject all the files above into this file
        new HtmlWebPackPlugin({
            template: './src/index.html'
        })
    ]


}

1 个答案:

答案 0 :(得分:0)

忘记了我在哪里找到了这个答案但是使用了webpack,如果我想让它工作,在我的组件中,我必须添加

moduleId: module.id,