我们最近升级到 Quasar 2,这导致 @vue/preload-webpack-plugin
抛出以下错误:
(node:14265) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tap' of undefined
- index.js:116
[myproject]/[@vue]/preload-webpack-plugin/src/index.js:116:65
- Hook.js:154 SyncHook.lazyCompileHook
[myproject]/[tapable]/lib/Hook.js:154:20
- Compiler.js:631 Compiler.newCompilation
[myproject]/[webpack]/lib/Compiler.js:631:26
- Compiler.js:667
[myproject]/[webpack]/lib/Compiler.js:667:29
- Hook.js:154 AsyncSeriesHook.lazyCompileHook
[myproject]/[tapable]/lib/Hook.js:154:20
- Compiler.js:662 Compiler.compile
[myproject]/[webpack]/lib/Compiler.js:662:28
- Watching.js:77
[myproject]/[webpack]/lib/Watching.js:77:18
quasar.conf.js
的相关部分:
extendWebpack (cfg) {
cfg.plugins.push(new PreloadWebpackPlugin({
rel: 'preload',
as (entry) {
if (/\.css$/.test(entry)) return 'style';
if (/\.woff$/.test(entry)) return 'font';
if (/\.png$/.test(entry)) return 'image';
return 'script';
}
}));
cfg.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/,
options: {
formatter: require('eslint').CLIEngine.getFormatter('stylish')
}
});
}
查看导致错误的 preload-webpack-plugin
行:
compiler.hooks.compilation.tap(
this.constructor.name,
compilation => {
// this line below
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap(
this.constructor.name,
(htmlPluginData) => {
if (skip(htmlPluginData)) {
return
}
this.generateLinks(compilation, htmlPluginData)
}
)
谁能建议如何解决这个问题?
环境: