问题描述
在我的远程服务器(Ubuntu 14.04 x64)上,每当我尝试使用我的捆绑包时,该过程只会返回Killed。当我不丑的时候,这很好。
有没有人遇到过这个问题?当我在本地Mac上执行它时,它没有问题(虽然我只是测试了它,耗时1.4分钟)。
这是我的webpack.config:
var webpack = require('webpack');
函数makeConfig(opts){
var config = {
entry:{
app:['./public/scripts/main.js '],
vendor:['lodash','react','react / lib / ReactCSSTransitionGroup','react-router','reqwest','d3']
},
stats:{
colors:true,
reason:true
},
输出:{
devtool:(opts.env = =='dev'?'#eval-source-map':''),
path:'dist / scripts',
文件名:'[name] .bundle.js'
},
插件:[
新的webpack.DefinePlugin({
ENV:opts.env
}),
新的webpack.optimize.CommonsChunkPlugin( 'vendor.bundle.js')
],
模块:{
加载器:[
{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.task('webpack',['cleanScripts'],function(done){
webpack(webpackConfig,function(err,stats){
if (err){
console.error(err);
抛出新的gutil.PluginError('webpack',err);
}
else {
done() ;
}
});
});
正如@barbuza所说,这是一个内存问题。我也使用只有512 MB RAM的数字海洋VPS(是的,我很便宜)。这对于webpack的uglify插件来说还不够。在服务器上添加2GB的交换空间解决了问题。我按照这篇文章来设置:
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.
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).
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;
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();
}
});
});
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上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!