2016-09-08 83 views
0

在下面的截圖中,您可以看到我們的網站加載了兩個主要的.js文件 - app & lib。我們的.js文件由webpack構建,並在底部生成而沒有//# sourceMappingURL=/path/to/script.js。也沒有像X-SourceMap: /path/to/script.js.map這樣的標題被返回。爲什麼webpack說它已經生成了一個源地圖,當它沒有?

那麼爲什麼Chrome會拋出關於嘗試獲取源映射的控制檯錯誤?

什麼是index.js?我們甚至沒有該文件在我們的網站上。

我們的網站是由服務器由http服務器節點模塊在一個Docker容器中,由nginx提供服務。

enter image description here


更新

下面德里克的回答表明的WebPack實際上已經加入到我們的輸出文件#sourcemap評論,即使它不產生sourcemap,也不是它要求生成一個。

那麼爲什麼webpack會在我們已編譯的app.js文件中引用一個不存在的sourcemap?

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 
    ] 
}; 
+0

我覺得這些sourcemaps來自我node_modules文件夾。所以作爲一個黑客來刪除它們,我在webpack完成後在我的最終輸出上運行:sed -i -e「s /#sourceMappingURL = // g」./app.js – Richard

回答

1

它加載的是因爲你的文件包含sourceMappingURL

enter image description here

+0

謝謝Derek!我附上了我們的webpack文件。我們沒有提到源地圖。爲什麼會嘗試添加一個? – Richard

+0

@理查德我不知道。根據文檔,如果您沒有將'devtool'設置爲'source-map',則不應該包含源地圖。 –

相關問題