javascript - 使用 babel 和 webpack 时如何生成 sourcemap?

标签 javascript webpack build-process babeljs source-maps

我是 webpack 的新手,我需要帮助设置以生成源映射。我从命令行运行 webpack serve ,编译成功。但我真的需要源图。这是我的 webpack.config.js

var webpack = require('webpack');

module.exports = {

  output: {
    filename: 'main.js',
    publicPath: '/assets/'
  },

  cache: true,
  debug: true,
  devtool: true,
  entry: [
      'webpack/hot/only-dev-server',
      './src/components/main.js'
  ],

  stats: {
    colors: true,
    reasons: true
  },

  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      'styles': __dirname + '/src/styles',
      'mixins': __dirname + '/src/mixins',
      'components': __dirname + '/src/components/',
      'stores': __dirname + '/src/stores/',
      'actions': __dirname + '/src/actions/'
    }
  },
  module: {
    preLoaders: [{
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
      loader: 'jsxhint'
    }],
    loaders: [{
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
      loader: 'react-hot!babel-loader'
    }, {
      test: /\.sass/,
      loader: 'style-loader!css-loader!sass-loader?outputStyle=expanded&indentedSyntax'
    }, {
      test: /\.scss/,
      loader: 'style-loader!css!sass'
    }, {
      test: /\.(png|jpg|woff|woff2)$/,
      loader: 'url-loader?limit=8192'
    }]
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]

};

我真的是 webpack 的新手,虽然文档并没有真正帮助我,因为我不确定这个问题具体是什么。

最佳答案

要使用源 map ,您应该更改 devtool选项 valuetruethis list 中可用的 value ,例如 source-map

devtool: 'source-map'

devtool: 'source-map' - A SourceMap is emitted.

关于javascript - 使用 babel 和 webpack 时如何生成 sourcemap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870830/

相关文章:

javascript - 如何检查对象数组是否具有重复的属性值?

javascript - 单击列表项无法显示下拉内容

javascript - 空的缩小 React 应用程序,为什么它已经很大了?

node.js - Webpack 没有创建它用来创建的 HTML 文件

visual-studio - 有没有办法根据 Visual Studio 中的构建配置指定程序集引用?

javascript - fast-csv 转换似乎正在剥离列

JavaScript : detect real IP address

javascript - 使用带有 chunkhash 的 webpack 的条件加载 polyfill

java - 我在 IntelliJ IDEA 中使用 Artifacts 有什么用?

powershell - 从 PowerShell 中的进程读取退出代码