Webpack 开发服务器使用 typescript 返回错误

问题描述 投票:0回答:0

我有一个 typescript 项目,当我运行

npm start
时,浏览器不会打开,我的
vscode
控制台没有显示任何错误,一切似乎都很好,当我在控制台中手动转到
http://localhost:8080/
时,我遇到了 404 错误:

获取本地主机:8080/ 404(未找到)

这是我的

webpack.config.js
文件:

const path = require('path');

module.exports = {
  mode: 'development',
  entry: './src/app.ts',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: 'dist',
  },
  devtool: 'inline-source-map',
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
};

tsconfig.json
文件:

{
  "compilerOptions": {
    "target": "es6",
    "module": "es2015",
    "lib": [
      "dom",
      "es6",
      "dom.iterable",
      "scripthost"
    ],
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "experimentalDecorators": true
  }
}

这是

package.json
文件:

{
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server",
    "build": "webpack"
  },
  "devDependencies": {
    "lite-server": "^2.5.4",
    "ts-loader": "^9.4.2",
    "typescript": "^5.0.4",
    "webpack": "^5.80.0",
    "webpack-cli": "^5.0.2",
    "webpack-dev-server": "^4.13.3"
  }
}

这是我的

script
文件中的
html
标签:

<script type="module" src="dist/bundle.js"></script>

这个配置有什么问题?

typescript webpack webpack-dev-server
© www.soinside.com 2019 - 2024. All rights reserved.