我使用HappyPack加快生产环境搭建速度,遇到问题,项目环境是vue-cli 4.0和webpack 4.0+,当我尝试使用命令'npm run build'构建项目时,它返回错误如下:
| Building for production...[hardsource:1e762ab3] Using 480 MB of disk space.
[hardsource:1e762ab3] Tracking node dependencies with: package-lock.json.
[hardsource:1e762ab3] Reading from cache 1e762ab3...
/ Building for production...Happy[happyBabel]: Version: 5.0.1. Threads: 8 (shared pool)
- Building for production...Happy[happyBabel]: All set; signaling webpack to proceed.
\ Building for production...
ERROR Failed to compile with 1 error 16:06:01
Syntax Error: Thread Loader (Worker 0)
HappyPack: unable to locate the plugin list! This most likely indicates an internal error.
我的配置文件“vue.config.js”看起来像:
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
const smp = new SpeedMeasurePlugin();
const HappyPack = require('happypack');
const os = require('os');
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
module.exports = {
runtimeCompiler: true,
productionSourceMap: false,
configureWebpack: smp.wrap(config => {
if (process.env.NODE_ENV === 'production') {
return {
module: {
rules: [
{
test: /\.js$/,
loader: 'happypack/loader?id=happyBabel',
exclude: /node_modules/
},
]
},
plugins: [
new HardSourceWebpackPlugin(),
new HappyPack({
id: 'happyBabel',
loaders: [{
loader: 'thread-loader',
}, {
loader: 'babel-loader?cacheDirectory=true',
}],
threadPool: happyThreadPool,
verbose: true,
})
]
}
} else {
return {
module: {
rules: [
{
test: /\.js$/,
loader: 'happypack/loader?id=happyBabel',
exclude: /node_modules/
},
]
},
plugins: [
new HappyPack({
id: 'happyBabel',
loaders: [{
loader: 'thread-loader',
}, {
loader: 'babel-loader?cacheDirectory=true',
}],
threadPool: happyThreadPool,
verbose: true,
})
],
}
}
}),
};
我不知道为什么它会抛出错误,它在开发模式下工作。请提供有关此问题的任何线程,谢谢您的帮助!