Webpack占用9GB内存是否正常?

时间:2017-10-10 21:22:08

标签: node.js webpack

根据Ubuntu node上的任务管理器,有8个进程正在运行900n到1.3GB的内存。

感觉太多了。幸运的是我的电脑有12GB的内存,但这太多了吗?如果是这样,任何想法为什么会这么多?

当webpack检测到更改并开始运行时,我的计算机每隔一段时间就会冻结并且有时打嗝。

webpack:^ 3.6.0,捆绑跟踪器:^ 0.2.0,仪表板:1.0.0-5,webpack-dev-server:^ 2.2.0,babel:^ 6.3.26

我正在使用WebpackDevServer:

new WebpackDevServer(webpack(config), {
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': 'Content-Type, Authorization, x-id, Content-Length, X-Requested-With',
        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS'
    },

    historyApiFallback: true,
    hot: true,
    publicPath: config.output.publicPath,
    quiet: true,    // Shows WebpackDashboard instead.
    watchOptions: {
        aggregateTimeout: 300,
        poll: 1000
    }
}).listen( ... );

这是我的webpack文件:

const config = {
    context: __dirname,

    devtool: 'eval-cheap-module-source-map',

    module: {
        loaders: [
            {
                test: /\.js[x]?$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.s[ac]ss$/,
                exclude: '/node_modules/',
                use: [{
                    loader: 'style-loader',
                    options: {
                        sourceMap: true
                    }
                }, {
                    loader: 'css-loader',
                    options: {
                        sourceMap: true
                    }
                }, {
                    loader: 'sass-loader',
                    options: {
                        sourceMap: true,
                        includePaths: [path.resolve(__dirname)]
                    }
                }]
            },
            {
                test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
                exclude: '/node_modules/',
                loader: 'file-loader'
            },
            {
                test: /\.(jpe?g|png|gif)$/,
                exclude: '/node_modules/',

                // If an image is less than 10kb, use data-url for images, otherwise
                // falls back to file-loader.
                loaders: ['url-loader?limit=10000&name=images/[hash:12].[ext]']
            }
        ]
    },

    resolve: {
        descriptionFiles: ['package.json'],
        extensions: ['.js', '.jsx', '.scss'],
        mainFiles: ['index'],
        modules: ['node_modules', path.resolve(__dirname)],
    }
};

config.entry = {
    main: [
        'react-hot-loader/patch',
        'babel-polyfill',
        './index.jsx',
        'webpack/hot/only-dev-server',
        `webpack-dev-server/client?http://${ localConfig.ip }:${ localConfig.port }`
    ]
};


config.output = {
    path: path.resolve('./dist/'),
    publicPath: `http://${ localConfig.ip }:${ localConfig.port }/assets/bundles/`,
    filename: '[name].js'
};


config.plugins = [
    new webpack.HotModuleReplacementPlugin(),

    new webpack.NoEmitOnErrorsPlugin(),

    // Used by Django.
    new BundleTracker({ filename: './webpack-stats-dev.json' }),

    new webpack.NamedModulesPlugin(),

    new DashboardPlugin(dashboard.setData)
];

如果有人知道一个很好的故障排除步骤列表,那将非常有用。

1 个答案:

答案 0 :(得分:2)

看起来你的进程需要1GB,但由于它们被执行8次,因为它们是单独的进程...然后它们需要8GB的内存。这就是线程获胜的地方。

如果测试有问题,可以强制GC。在我的情况下,建筑是非常快的。获取依赖项需要时间,并且测试执行也很昂贵。如果您的情况也是如此,请查看here

  

如果我每100个请求手动调用gc(),则RSS不会超过70   MIB。

正如你所写的,难题。我认为你处在边缘。