由于项目较老,所以webpack一直没更新,一直用的是1.14.0版本的
终端输入cnpm run build进行打包时,打包到一半时就不会动了,提示下面
54% 810/1094 build modules
下图是webpack配置,以前负责项目那些人配置的
const webpack = require('webpack');
const globalConfig = require('./src/config.js');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const port = 10;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const babelLoaderConfig = {
presets: ['latest', 'stage-0', 'react'],
plugins: [['import', {libraryName: 'antd', style: true}]],
cacheDirectory: true,
};
const lessLoaderVars = {
sidebarCollapsible: globalConfig.sidebar.collapsible,
};
module.exports = {
devtool: 'eval-source-map',
entry: [
'webpack-dev-server/client?http://0.0.0.0:'+port, // WebpackDevServer host and port
'webpack/hot/only-dev-server',
'babel-polyfill',
'./src/index.js',
],
output: {
path: __dirname + '/dist',
filename: 'bundle.js',
},
resolve: {
modulesDirectories: ['node_modules', './src'],
extensions: ['', '.js', '.jsx'],
alias: {
antdcss: 'antd/dist/antd.min.css',
},
},
module: {
loaders: [ // 定义各种loader
{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel-loader?' + JSON.stringify(babelLoaderConfig)],
exclude: /node_modules/,
}, {
test: /\.css$/,
loader: 'style!css',
}, {
test: /\.less$/,
loader: 'style!css!' + `less?{"sourceMap":true,"modifyVars":${JSON.stringify(lessLoaderVars)}}`,
}, {
test: /\.(png|jpg|svg)$/,
loader: 'url?limit=25000',
},
],
},
devServer: {
contentBase: './',
host: '172.16.225.39',
port: port,
historyApiFallback: true, //不跳转
inline: true, //实时刷新
},
plugins: [
new webpack.BannerPlugin('This file is created by jxy'),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__DEV__: JSON.stringify(JSON.parse(process.env.NODE_ENV === 'production' ? 'false' : 'true')),
}),
new HtmlWebpackPlugin({
template: 'index.html.template',
title: globalConfig.name,
favIcon: globalConfig.favicon,
devMode: true,
}),
new OpenBrowserPlugin({ url: 'http://172.16.225.39:'+port })//自动用默认浏览器打开项目
],
};