2016-09-08 1 views
0

Im Screenshot unten können Sie sehen, dass unsere Website zwei Hauptdateien .js lädt - App & lib. Unsere .js-Dateien werden von Webpack erstellt und für die Produktion ohne am Ende von ihnen ausgegeben. Es gibt auch keinen Header wie X-SourceMap: /path/to/script.js.map zurückgegeben wird.Warum sagt Webpack, dass es eine Quellkarte erzeugt hat, wenn nicht?

Warum wirft Chrome einen Konsolenfehler beim Versuch, Quellkarten zu erhalten?

Und was ist index.js? Wir haben diese Datei nicht einmal auf unserer Website.

Unsere Website ist Server von http-Server-Knoten-Modul in einem Docker-Container, von Nginx bedient.

enter image description here


aktualisieren

Dereks Antwort unten zeigt, dass webpack hat in der Tat einen #sourcemap Kommentar zu unserer Ausgabedatei hinzugefügt, auch wenn es keine sourcemap erzeugt hat, noch war es wurde gebeten, eins zu generieren.

Warum legt Webpack einen Verweis auf eine nicht vorhandene Quellkarte in unserer kompilierten app.js-Datei ab?

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

Ich denke, diese sourcemaps aus meinem node_modules Ordner kommen. Also als einen Hack, um sie zu entfernen, führe ich dies auf meiner endgültigen Ausgabe aus, nachdem das Webpack fertig ist: sed -i -e "s/# sourceMappingURL = // g" ./app.js – Richard

Antwort

1

Es wird geladen, dass, weil die Dateien sourceMappingURL enthalten:

enter image description here

+0

Danke Derek! Ich habe unsere Webpack-Datei angehängt. Quellmaps werden nicht erwähnt. Warum sollte es versuchen, eins hinzuzufügen? – Richard

+0

@Richard Ich habe keine Ahnung. Laut der Dokumentation sollte es keine Quellkarten enthalten, wenn Sie 'devtool' nicht auf' source-map' gesetzt haben. –

Verwandte Themen