版本3.0.5
复制链接https://github.com/clark-cui/vue3-problem
再生纱线的步骤
npm运行开发
期望的是什么?devServer工作成功。
到底发生了什么?找不到模块:错误:无法解决'F:\workspace_github\vue3-problem‘中的'vue’
我没有使用vue-cli或vite来构建这个存储库。
所以我使用"vue-loader":"^16.1.2“和”@vue/编译器-sfc“:"^3.0.0”来解析“.VUE”。
如果我使用cdn导入vue.Then,会出现这样的错误。
如果我使用npm导入vue.This,问题就解决了。
这在vue2中没有发生,我猜这是vue编译器的错误。
我想使用vue和cdn.How来解决这个问题?
发布于 2021-01-27 15:32:58
为了在CDN中使用vue,您必须配置externals以告知webpack使用外部的the。此外,为了使其正常工作,您还需要对以下内容进行一些改进:
// webpack.config.js
module.exports = {
// ...
externals: {
// tell `webpack` to resolve `vue` from root (window)
vue: "Vue",
},
devServer: {
// ...
// might have to turn of this option since it throws error
// not sure where it comes from though :(
hot: false,
}
}稍微改进一下模板:
// index.html
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Move the script to here to ensure load `Vue` before your script -->
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.0/vue.global.prod.js"></script>
<title>Vue demo</title>
</head>
<body>
<noscript>
<strong>error</strong>
</noscript>
<div id="app"></div>
</body>
</html>https://stackoverflow.com/questions/65912099
复制相似问题