I am trying to get Angular 2 + Webpack working - and I am almost there :)
The last problem i need to solve is:
When browsing a child route (e.g. /childroute/main) everything works as intended, as long as I use router-links.
When entering the adress manually or doing a reload i get a 404 with wrong bundle paths..
It should be localhost:5001/dist/bundle.js , but webpack tries to get localhost:5001/childroute/dist/bundle.js . Changing my publicPath in webpack did not work :(
Here is my webpack config:
"use strict";
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: {
"app": "./wwwroot/app/base/boot",
"vendor": "./wwwroot/app/base/vendors"
},
devtool: 'source-map',
output: {
filename: "bundle.js",
chunkFilename: "[id]chunk.js",
path: "./wwwroot/dist/",
publicPath: "./dist/"
},
//devServer: {
// contentBase: "./wwwroot/",
// host: "localhost",
// port: 50001,
// inline:true
//},
resolve: {
extensions: ['','.js','.ts']
},
module: {
loaders: [
//Typescript
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: '/node_modules/'
},
// SASS
{
test: /\.scss$/,
loaders: ['style','css','sass'],
exclude: '/node_modules/'
},
// Fonts & Files
{
test: /\.(ttf|eot|txt|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'file-loader' ,
exclude: '/node_modules/'
}
]
},
plugins: [
//new webpack.optimize.UglifyJsPlugin({
// compressor: {
// warnings: false
// }
//}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new webpack.optimize.CommonsChunkPlugin("vendor","vendor_bundle.js")
]
};
I hope someone could give me a hint :)
Thanks guys!
Edit: If I change script paths in index.html from "dist/bundle.js" to "/dist/bundle.js", I get the scripts loaded, but angular does not find my templates then... same error with an additional "/childroute/" in template path..