为什么Webpack bundle.js在同构应用程序中传输了两次?

时间:2017-04-06 15:18:57

标签: webpack bundle isomorphic-javascript

我注意到在生产中,bundle.js文件被传输两次。 bundle.js文件本身第二次请求..是默认配置还是配置相关?

另请注意,第二次请求bundle.js只需要192ms,第一次远小于634ms。也许是因为文件被缓存了。

注意:这是一个同构的应用程序, restify 可以提供所有资产文件。

查看下面的屏幕截图: enter image description here

一些webpack生产设置即时使用:

module.exports = {
    devtool: false,
    output: {
        path: resolve(__dirname, 'dist', 'www'),
        publicPath: '/www/',
        filename: 'bundle.js',
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            mangle: true,
            compress: {
                warnings: true,
                screw_ie8: true,
                conditionals: true,
                unused: true,
                comparisons: true,
                sequences: true,
                dead_code: true,
                evaluate: true,
                if_return: true,
                join_vars: true,
            },
            output: {
                comments: false,
            },
        }),
        new ExtractTextPlugin('styles.css'),
    ],
    module: {
        loaders: [{
            test: /\.js$/,
            loader: 'babel-loader',
            include: resolve(__dirname, 'src', 'main'),
            exclude: /node_modules/,
        }, {
            test: /\.*css$/,
            loader: ExtractTextPlugin.extract({
                fallback: 'style-loader', use: 'css-loader?-autoprefixer!sass-loader',
            }),
        }],
    }
};

1 个答案:

答案 0 :(得分:1)

此问题与打开Chrome Developer工具时获取sourceMaps有关。我使用Charles Proxy作为另一个SO问题(https://stackoverflow.com/a/30777461/2400247)的答案进行了测试,事实上, bundle.js 只下载了一次。

检查下面的查尔斯测试

enter image description here

希望它有助于其他开发者。

相关问题