Webpack Uglify 插件返回“Killed"在 Ubuntu 上 [英] Webpack Uglify plugin returns "Killed" on Ubuntu

查看:25
本文介绍了Webpack Uglify 插件返回“Killed"在 Ubuntu 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的远程服务器(Ubuntu 14.04 x64)上,每当我尝试丑化我的捆绑包时,该过程只会返回Killed".我不丑化的时候就好了.

On my remote server (Ubuntu 14.04 x64), whenever I try to uglify my bundles, the process simply returns "Killed". When I don't uglify, it's just fine.

有人遇到过这种情况吗?当我在本地 Mac 上执行此操作时,一切正常(尽管我刚刚测试了它并花了 1.4 分钟).

Has anyone run into this? When I do it on my local Mac, it's fine (although I just tested it and it took 1.4 mins).

这是我的 webpack.config:

This is my webpack.config:

var webpack = require('webpack');

function makeConfig(opts) {
    var config = {

        entry: {
            app: ['./public/scripts/main.js'],
            vendor: ['lodash', 'react', 'react/lib/ReactCSSTransitionGroup', 'react-router', 'reqwest', 'd3']
        },

        stats: {
            colors: true,
            reasons: true
        },

        output: {
            devtool: (opts.env === 'dev' ? '#eval-source-map' : ''),
            path: 'dist/scripts',
            filename: '[name].bundle.js'
        },

        plugins: [
            new webpack.DefinePlugin({
                ENV: opts.env
            }),
            new webpack.optimize.CommonsChunkPlugin('vendor.bundle.js')
        ],

        module: {
            loaders: [
                { test: /.jsx?$/, loader: 'jsx-loader' }
            ]
        }
    };

    if(opts.env === 'prod') {
        config.plugins.push(
            new webpack.optimize.UglifyJsPlugin(),
            new webpack.optimize.DedupePlugin()
        );
    }

    return config;
}

module.exports = makeConfig;

它被 gulp 调用,如下所示:

and it's called by gulp like so:

gulp.task('webpack', ['cleanScripts'], function(done) {
    webpack(webpackConfig, function(err, stats) {
        if(err) {
            console.error(err);
            throw new gutil.PluginError('webpack', err);    
        }
        else {
            done();
        }
    });
});

推荐答案

正如@barbuza 所建议的,这是一个内存问题.我也在使用只有 512 MB RAM 的 Digital Ocean VPS(是的,我很便宜).这对于 webpack 的 uglify 插件来说还不够.在服务器上添加 2GB 的交换空间解决了这个问题.我按照这篇文章进行了设置:https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

As @barbuza suggested, it was a memory issue. I too am using a Digital Ocean VPS that only has 512 MB of RAM (yes, I'm cheap). That's not enough for webpack's uglify plugin. Adding 2GB of swap space on the server solved the issue. I followed this article to set that up: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

这篇关于Webpack Uglify 插件返回“Killed"在 Ubuntu 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆