为什么webpack说它没有生成源地图?

时间:2016-09-08 14:25:53

标签: javascript node.js webpack httpserver source-maps

在下面的屏幕截图中,您可以看到我们的网站加载了两个主要的.js文件 - app&库。我们的.js文件是由webpack构建的,并在其底部没有//# sourceMappingURL=/path/to/script.js的情况下输出生产。也没有像X-SourceMap: /path/to/script.js.map这样的标题被返回。

那么为什么Chrome会尝试获取源地图时出现控制台错误?

什么是index.js?我们的网站上甚至没有该文件。

我们的站点是由Docker容器中的http-server节点模块提供的服务器,由nginx提供。

enter image description here

更新

Derek的回答显示,webpack实际上已经为我们的输出文件添加了一个#sourcemap注释,即使它没有生成源图,也没有要求生成一个。

那么为什么webpack会在我们编译的app.js文件中引用一个不存在的源图?

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');
var rootPath = __dirname; // e.g.  ~/projects/ekaya
var srcPath = path.join(rootPath, 'src');
var distPath = path.join(rootPath, '../dist/client_gumtree/app');
var shared

Path = path.resolve('../shared');

module.exports =
{
  bail: true,
  cache: false,
  context: rootPath,
  debug: false,
  //devtool: 'source-map', //inline-source-map, https://webpack.github.io/docs/configuration.html#devtool
  target: 'web', //node, web
  // devServer:
  // {
  //   contentBase: distPath,
  //   historyApiFallback: true,
  //   outputPath: path.join(distPath, 'devServer'),
  //   hot : true,
  // },
  entry:
  {
    app: ['babel-polyfill', path.join(srcPath, 'core/index.ts')],
    lib: ['babel-polyfill', 'react', 'react-router', 'react-dom', 'lodash', 'history',
          'react-redux', 'redux-thunk', 'redux-api-middleware', 'redux']
  },
  output:
  {
    path: distPath,
    publicPath: '',
    filename: '/[name].js',
    pathInfo: true
  },
  resolve:
  {
    root: srcPath,
    extensions: ['', '.js',  '.jsx', '.ts', '.tsx'],
    modulesDirectories: ['node_modules', srcPath, 'typings']
  },
  module:
  {
    loaders:
    [
      {test: /\.js$/, loader: 'babel-loader?cacheDirectory', include: [srcPath, sharedPath]},
      {test: /\.jsx$/, loader: 'babel-loader?cacheDirectory', include: [srcPath, sharedPath]},
      {test: /\.ts$/, loader: 'babel-loader!ts-loader?cacheDirectory', include: [srcPath, sharedPath]},
      {test: /\.tsx$/, loader: 'babel-loader!ts-loader?cacheDirectory', include: [srcPath, sharedPath]},
      {test: /\.json$/, loader: 'json-loader'},
      {test: /\.scss$/, loaders: [
        'style?sourceMap',
        'css?modules&importLoaders=1&localIdentName=[name]-[local]---[hash:base64:5]',
        'cssnext',
        'resolve-url',
        'sass?sourceMap'
      ]},
      {test: /\.png$/, loader: 'file-loader'},
      {test: /\.jpg$/, loader: 'file-loader'},
      {test: /\.jpeg$/, loader: 'file-loader'},
      {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=image/svg+xml&name=/[name].[ext]'},
      {test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff&name=/[name].[ext]"},
      {test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff&name=/[name].[ext]"},
      {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/octet-stream&name=/[name].[ext]"},
      {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?name=/[name].[ext]"}
    ]
  },
  plugins:
  [
    new webpack.DefinePlugin({}) //these are our config settings & are injected in the build script when calling webpack using --define
    ,new CopyWebpackPlugin([ { from: path.join(srcPath, 'images'), to: 'images' } ]) //copy images to the build folder unchanged
    ,new HtmlWebpackPlugin({ inject: true, template: path.join(srcPath, 'index.html')  }) // this puts our script file into the main html page
    ,new webpack.NoErrorsPlugin() // don't emit bundles with errors
    ,new webpack.optimize.CommonsChunkPlugin('lib', '/lib.js')  // share common files
    ,new webpack.optimize.DedupePlugin() // share common files
    ,new webpack.optimize.AggressiveMergingPlugin()
  //  ,new webpack.optimize.UglifyJsPlugin({ sourceMap: false, mangle: false, minimize: true, beautify: false, comments: false,}) //Can't get this to work without error, so instead we uglify manually in the build script after webpack has run
  ]
};

1 个答案:

答案 0 :(得分:1)

正在加载,因为您的文件包含sourceMappingURL

enter image description here