I'm trying to add hot module reloading into my typescript project. I have the following settings:
package.json
"start": "webpack-dev-server"
tsconfig.js
{
"compilerOptions": {
"outDir": "/public/",
"target": "es5",
"noImplicitAny": true,
"experimentalDecorators": true,
"sourceMap": true,
"jsx": "react"
},
"include": [
"./src/**/*"
]
}
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var publicFolder = path.join(__dirname, 'public');
var sourceFolder = path.join(__dirname, 'src');
module.exports = {
devtool: 'source-map',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./src/index.tsx',
],
output: {
filename: 'bundle.js',
path: publicFolder,
publicPath: publicFolder,
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
},
module: {
loaders: [
{
test: /\.tsx?$/,
loaders: ['react-hot', 'awesome-typescript'],
include: sourceFolder,
},
],
preLoaders: [
{
test: /\.js$/,
loader: 'source-map-loader',
include: sourceFolder,
},
],
},
devServer: {
colors: true,
port: 3000,
hot: true,
inline: true,
progress: true,
historyApiFallback: true,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
};
I get the following error message in my explorer:
GET http://localhost:3000/public/bundle.js 404 (Not Found)
It seems that the public path is wrongly defined. Please can you help me what am I doing wrong?
Your
output.publichPath
is incorrect. It should be an url:publicPath: '/public/'
. Not a path on your local filesystem.From the webpack documentation
Webpack dev server will generate an in memory bundle and serve it from
output.publicPath
From webpack dev server documentation