我正在尝试配置webpack与typescript和handlebars一起使用。我还添加了webpack-dev-server,但它无法正常工作。它显示所有内容都在运行,但当我访问localhost:6000时,会出现“此网站无法访问”的错误提示。
这是我的目录树:
这是我的目录树:
│ package.json
│ tsconfig.json
│ webpack.config.js
│
├───dist
│ bundle.js
│ bundle.js.map
│ index.html
│
└───src
index.handlebars
index.ts
templates.d.ts
这里是webpack.config.js文件
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: './src/index.ts',
devtool: 'source-map',
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
hot: true,
host: '0.0.0.0',
port: 6000,
open: true
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/'
},
resolve: {
extensions: ['.ts', '.js' ]
},
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
handlebarsLoader: {}
}
}),
new HtmlWebpackPlugin({
title: 'My hometask',
template: './src/index.handlebars'
})
],
module: {
rules: [
{
test: /\.js/,
loader: 'babel',
exclude: /(node_modules|bower_components)/
},
{
test: /\.handlebars$/,
loader: "handlebars-loader"
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
]
}
};
这有什么问题吗?为什么我不能使用dev-server?