这是我的webpack.config.js
,我没有看到任何奇怪的东西(即无限线程池),这将创建一个挂起,但我总是要手动Ctrl+C的步骤继续。这是一个小麻烦,但我想解决它,同时重构一些部署代码。
const path = require('path');
const version = require('./VERSION').version;
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
module.exports = {
mode: process.env.NODE_ENV,
entry: './client/index.js',
output: {
filename: 'client.js',
libraryTarget: 'var',
library: 'ui',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-flow'],
},
},
},
],
},
plugins: [
new SentryWebpackPlugin({
include: '.',
ignoreFile: '.sentrycliignore',
ignore: [
'node_modules',
'lib',
'server',
'flow-typed',
'scripts',
'webpack.config.js'
],
configFile: 'sentry.properties',
release: version
})
],
watch: true,
watchOptions: {
ignored: ['test', 'node_modules', 'scripts'],
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
publicPath: '/dist/',
},
};
下面是我的package.json
的外观:
{
"name": "investomation-api",
"version": "0.0.1",
"description": "...",
"private": true,
"main": "server.js",
"scripts": {
"build": "NODE_ENV=production npm install && webpack --mode production",
"start": "PORT=443 NODE_ENV=production pm2 start server/start.js",
"restart": "pm2 restart 0",
"start:dev": "PORT=3002 NODE_ENV=development nodemon server/dev-start.js",
"flow": "flow",
"server:upload": "cd scripts && ./upload"
},
"repository": {
"type": "git",
"url": "..."
},
"nodemonConfig": {
"ignore": [
"cypress/",
"node_modules/",
"scripts/",
"tests/"
]
},
"prettier": {
"tabWidth": 4
},
"author": "Alexander Tsepkov",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@mapbox/geojson-types": "^1.0.2",
"bcrypt": "^3.0.7",
"body-parser": "^1.19.0",
"connect-flash": "^0.1.1",
"connect-sqlite3": "^0.9.11",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"csv-parser": "^2.3.2",
"d3": "^5.15.0",
"dialog-polyfill": "^0.5.0",
"dotenv": "^8.2.0",
"ejs": "^2.7.4",
"express-session": "^1.17.0",
"https": "^1.0.0",
"knex": "^0.21.1",
"morgan": "^1.9.1",
"multer": "^1.4.2",
"node-fetch": "^2.6.0",
"nodemailer": "^6.4.2",
"objection": "^2.1.3",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"sharp": "^0.25.4",
"sqlite3": "^4.1.1",
"stripe": "^7.15.0"
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/node": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@babel/preset-flow": "^7.8.3",
"@babel/register": "^7.8.3",
"@sentry/webpack-plugin": "^1.9.3",
"babel-loader": "^8.0.6",
"css.escape": "^1.5.1",
"cypress": "^4.5.0",
"flow-bin": "^0.107.0",
"html-webpack-plugin": "^3.2.0",
"jsdom": "^15.2.1",
"mocha": "^6.2.2",
"nodemon": "^1.19.4",
"test-drone": "0.0.13",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1"
}
}
我通过npm run build
生成进程,client.js
被正确构建,但是webpack构建进程从未终止。
3条答案
按热度按时间dxxyhpgq1#
我解决了我的问题。我在开发和生产中使用了相同的webpack配置。在开发中,它被配置为监视文件更改并重新启动服务器。我没有意识到这也意味着它在生产中监视文件更改,准备重新构建bundle。将
watch: true
改为watch: process.env.NODE_ENV !== 'production' && true
修复了这个问题。r8uurelv2#
这可能是由于 webpack-bundle-analyzer 插件造成的。请停用或移除此插件以进行生产建置。
olmpazwi3#
嗨,我一直在纠结这个问题,但我想通了:)
Webpack5将停留在监视模式,我们需要一种方法来确定它何时完成。你可以在这里使用我的解决方案对你的webpack.config文件,输入到插件数组。将退出监视模式,并将继续下一步:)希望这对你的工作