Вы можете сделать это с webpack devServer
Вот пример:
package.json
{
"name": "sampleApp",
"version": "1.0.0",
"description": "",
"devDependencies": {
"webpack": "4.15.0",
"webpack-cli": "3.0.8",
"webpack-dev-server": "3.1.4"
},
"scripts": {
"dev": "webpack --mode development && webpack-dev-server --mode development",
"build": "webpack --mode production && webpack-dev-server --mode production"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sample/sample.git"
}
}
webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
},
devServer: {
contentBase: path.resolve(__dirname, './'),
publicPath: '/build/',
host: '127.0.0.1',
port: 9998,
open: true
},
resolve: {
extensions: ['.ts', '.js'],
}
};