我正在尝试将vuejs 3集成到一个使用webpack的现有项目中。我读过关于vue-loader的文章,所以我试着用它。
在正式文件中,我有以下几点:
每次发布新版本的vue时,都会同时发布相应版本的vue模板编译器。编译器的版本必须与基本的vue包同步,这样vue加载程序就可以生成与运行时兼容的代码。这意味着每次在项目中升级vue时,都应该升级vue模板编译器以匹配它。
因此,当我试图编译时,会得到以下错误:
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-编译器@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我该如何解决这个问题?
发布于 2020-11-17 18:21:36
要使vue 3与webpack一起很好地工作而不使用vite或vue cli,请执行以下步骤:
package.json中:{
"private": true,
"name": "vue-3",
"description": null,
}npm i --save vue@next vue-loader@next
@vue/compiler-sfc,它取代了vue-template-compilernpm i -D @vue/compiler-sfc css-loader file-loader mini-css-extract-plugin
url-loader webpack webpack-cli webpack-dev-serverconst path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = (env = {}) => ({
mode: env.prod ? "production" : "development",
devtool: env.prod ? "source-map" : "cheap-module-eval-source-map",
entry: [
require.resolve(`webpack-dev-server/client`),
path.resolve(__dirname, "./src/main.js")
].filter(Boolean),
output: {
path: path.resolve(__dirname, "./dist"),
publicPath: "/dist/"
},
resolve: {
alias: {
// this isn't technically needed, since the default `vue` entry for bundlers
// is a simple `export * from '@vue/runtime-dom`. However having this
// extra re-export somehow causes webpack to always invalidate the module
// on the first HMR update and causes the page to reload.
vue: "@vue/runtime-dom"
}
},
module: {
rules: [
{
test: /\.vue$/,
use: "vue-loader"
},
{
test: /\.png$/,
use: {
loader: "url-loader",
options: { limit: 8192 }
}
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: { hmr: !env.prod }
},
"css-loader"
]
}
]
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
})
],
devServer: {
inline: true,
hot: true,
stats: "minimal",
contentBase: __dirname,
overlay: true,
injectClient: false,
disableHostCheck: true
}
});dev脚本以运行应用程序:{
"private": true,
"scripts": {
"dev": "webpack-dev-server"
},
"dependencies": {
"vue": "^3.0.2"
},
"name": "vue-3",
"description": null,
"devDependencies": {
...
}
}index.html:<link rel="stylesheet" href="/dist/main.css" />
<div id="app"></div>
<script src="/dist/main.js"></script>终于运行npm run dev访问http://localhost:8080/
对于准备使用的项目,请尝试克隆此储存库,该是按照上述步骤构建的。
发布于 2020-11-17 09:31:47
我相信你需要在Vue 3中使用vue-加载器@next
在Vue 3中,SFC编译器包不再是vue-template-compiler,而是compiler-sfc (检查这里)。
我完全同意使用Vue CLI来管理项目的建议--这将为您管理所有依赖项(特别是现在Vue 3生态系统试图赶上Vue 3发行版和许多工具甚至没有任何迁移文档....like vue-加载器时)节省很多麻烦。
如果您无法使用CLI,因为您的现有项目已经具有Webpack配置,则仍然可以使用CLI作为指导。只需在旁边生成新项目,使用vue inspect命令检查它正在使用的Webpack配置,并检查所需依赖项的package.json .
发布于 2021-01-17 19:06:59
我刚刚在rails中安装了Webpacker,它附带了安装Vue的好任务。
尽管如此,它用它的加载程序和模板编译器安装Vue 2.x .
要将所有内容切换到Vue 3,以及它的依赖项,只需运行:
yarn add vue@next vue-loader@next @vue/compiler-sfc
瞧!你现在用的是Vue 3
https://stackoverflow.com/questions/64868632
复制相似问题