我正在尝试将 vuejs 3 集成到使用 webpack 的现有项目中。我阅读了有关 vue-loader 的信息,因此我正在尝试使用它。
在官方文档中我有这个:
每次发布新版本的vue,都会同时发布对应版本的vue-template-compiler。编译器的版本必须与基本的 vue 包同步,以便 vue-loader 生成与运行时兼容的代码。这意味着每次在项目中升级 vue 时,都应该升级 vue-template-compiler 以匹配它。
所以,当我尝试编译时,我得到了这个错误:
Vue packages version mismatch:
- vue@3.0.2 (/home/alejo/playground/parquesFrontend/node_modules/vue/index.js)
- vue-template-compiler@2.6.12 (/home/alejo/playground/parquesFrontend/node_modules/vue-template-compiler/package.json)
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.
但是当我尝试安装 vue-template-compiler@3.0.2 我得到这个错误:
❯ npm install vue-template-compiler@3.0.2
npm ERR! code ETARGET
npm ERR! notarget No matching version found for vue-template-compiler@3.0.2.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/alejo/.npm/_logs/2020-11-17T02_52_46_458Z-debug.log
我怎么解决这个问题?
原文由 Alejo Dev 发布,翻译遵循 CC BY-SA 4.0 许可协议
要使 vue 3 在不使用 vite 或 vue cli 的情况下与 webpack 一起正常工作,请执行以下步骤:
package.json
像:npm i --save vue@next vue-loader@next
@vue/compiler-sfc
的开发依赖项,它取代了vue-template-compiler
dev
脚本来运行您的应用程序:index.html
:最后 运行
npm run dev
访问http://localhost:8080/对于准备使用的项目,请尝试克隆按照上述 步骤 构建的存储库。