chungtinhlakho chungtinhlakho - 2 months ago 44
Node.js Question

angular2/webpack template 404 errors

I followed this tutorial and got everything just like the tutorial. https://www.youtube.com/watch?v=4i1nLrqMR14#t=563.837081

Now it's time to grow my application so I created an html file for my component, and set my templatURL to

templateUrl: './app.html'
since it's in the same directory which is root/app/app.html. I received an error because it's looking for it at root/app.html. See attachment for project structure and error.

Command for dev change tracking:

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'
})
]


}

Answer

Lost track of where I found this answer but with webpack, If I want it to work, in my component, I have to add

moduleId: module.id,
Comments