在Google Compute Engine上构建时,Webpack挂起

时间:2018-09-05 06:19:57

标签: webpack

不确定以前是否有人经历过。 npm run build(基本上是webpack --display-error-details)可以在我的本地计算机上正常工作,也可以在Google Compute Engine上工作。这些天突然间,它真的很慢,并且最终挂在了构建过程上。我正在使用Google Compute Engine的免费层。我怀疑是否是因为机器的性能...

这是我的package.json和配置:

{
    ...
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5"
  },
  "scripts": {
    "start": "webpack-dev-server",
    "build": "webpack --display-error-details"
    ...
  }

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const ExtractTextPlugin = require('extract-text-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const srcDir = 'src';
const tgtDir = 'dist';
const srcFullPath = path.join(__dirname, srcDir);
const tgtFullPath = path.join(__dirname, tgtDir);
console.log(webpack.SplitChunksPlugin);
module.exports = {
	mode: 'development',
	entry: {
		polyfill: ['babel-polyfill'],
		module: path.join(srcFullPath, 'index.jsx')
	},
	devtool: 'eval-source-map',// for production, refer to https://webpack.js.org/configuration/devtool/
	devServer:{
		contentBase: tgtDir,
		port: 8888,
		host: '0.0.0.0',
		historyApiFallback: true,
		hot:false,
		inline:false
		// ,
		// public: 'www.namwkim.org:8888'
	},
	resolve: {
		modules: [srcFullPath, 'node_modules'], //resolved to ./
		extensions:['.js', '.jsx']
	},
	output: {
		path: tgtFullPath, // Path to where webpack will build stuffs
		publicPath: '/', // This is used to generate URLs to e.g. images
		filename: '[name].js' // This is used to name bundled files from entry points.
	},
	module: {
		rules: [{
			test:/\.(js|jsx)$/,
			enforce: 'pre',
			loader: 'eslint-loader',
			include: srcFullPath,
			options: {
				failOnWarning: false,
				failOnError: true,
				fix: true
			}
		},
		{
			test: /\.(js|jsx)$/,///\.js?$/,
			// exclude: /node_modules/,
			include: srcFullPath,
			loader: 'babel-loader',
			options: {
				plugins: ['transform-runtime','transform-object-rest-spread'],
				presets: ['react', 'env'] //['env'],stage-0 es7 support? async etc
			}
		},
		// {
		// 	test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
		// 	loader: 'url-loader?limit=10000&mimetype=application/font-woff'
		// },
		// {
		// 	test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
		// 	loader: 'file-loader?outputPath=assets/files/'
		// },
		{
			test: /\.css$/,
			use: [
				MiniCssExtractPlugin.loader,
				{
					loader:'css-loader',
					options:{
						modules: true,
						localIdentName: '[local]--[hash:base64:7]'
					}
				}
			]

		}
		]
	},
	plugins: [
		new MiniCssExtractPlugin({
			// Options similar to the same options in webpackOptions.output
			// both options are optional
			filename: './css/[name].css',
			chunkFilename: './css/[id].css'
		}),
		// new webpack.optimize.CommonsChunkPlugin({
		// 	name: 'vendor',
		// 	minChunks: function (module) {
		// 		// this assumes your vendor imports exist in the node_modules directory
		// 		return module.context && module.context.indexOf('node_modules') !== -1;
		// 	}
		// }),
		//CommonChunksPlugin will now extract all the common modules from vendor and main bundles
		// new webpack.optimize.CommonsChunkPlugin({
		// 	name: 'manifest' //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
		// }),
		// new ExtractTextPlugin('./css/[name].css'),

		new HtmlWebpackPlugin({
			filename: 'index.html',
			template: path.join(__dirname, 'src/index.html')
		}),
		new CopyWebpackPlugin([
			{
				from: 'src/assets',
				to: 'assets',
				force: true
			}]
		),
		new webpack.NoEmitOnErrorsPlugin(),
		new webpack.LoaderOptionsPlugin({
			debug: true
		})
	]
};

Image showing the status on Google Compute Engine

0 个答案:

没有答案