【问题标题】:Webpack 4 and ts-loader not generating map filesWebpack 4 和 ts-loader 不生成地图文件
【发布时间】:2018-09-19 10:20:38
【问题描述】:

我在这里做错了什么?

运行webpack -d --config webpack.config.js 捆绑文件时不要创建映射文件。

webpack.config.js

const path = require('path');   
module.exports = {
  mode: "development",
  devtool: "inline-source-map",
  entry: './server/server.ts',
  output: {
    filename: 'server.js',
    path: path.resolve(__dirname, 'dist')
  },
  resolve: {
    extensions: [ '.tsx', '.ts', '.js' ]
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
  },
  target: 'node',
  node: {
    console: true,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};

tsconfig.json

{
  "files": [
    "server/server.ts"
  ],
  "include": [
    "server/**/*.ts"
  ],
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "target": "es6",
    "outDir": "dist",
    "rootDir": "server",
    "sourceMap": true,
    "baseUrl": ".",
    "moduleResolution": "node",
    "removeComments": true,
    "typeRoots": [ "node_modules/@types" ],
    "paths": {
      "*": [
        "node_modules/@types/*",
        "./server/types/*"
      ]
    }
  }
}

server.js 已创建,但缺少地图文件。每次我运行webpack -d --config webpack.config.js 时都不会创建地图文件。

版本:

webpack 4.5.0

tsloader 4.2.0

【问题讨论】:

    标签: typescript webpack ts-loader


    【解决方案1】:

    devtool 设置为inline-source-map;因此,您的源映射包含在 JS 文件中作为内联注释。如果要生成单独的地图文件,请将devtool 更改为sourcemap

    【讨论】:

      猜你喜欢
      • 2019-05-27
      • 2020-06-30
      • 2017-03-18
      • 2017-05-27
      • 2015-11-19
      • 2017-11-18
      • 2017-06-26
      • 1970-01-01
      • 2018-09-21
      相关资源
      最近更新 更多