把一个Vue项目的页面打包后再另一个项目中使用

步骤:

1.项目1新建一个js文件,引入我们需要使用的vue页面:

复制代码
// 引入组件
import indexVue from './index.vue'

// install
indexVue.install = function (Vue) {
  Vue.component("indexVue", indexVue)
  // Vue.component(FlowEditorVue.name, FlowEditorVue)
}


// 导出
export default indexVue

2.在项目1的package.json中添加命令将刚才导出的vue页面进行打包;

复制代码
"lib": "vue-cli-service build --mode prod --target lib --name indexVue --dest lib src/views/workflow/work/index.js"

3.在你需要使用的项目中将打包后的lib目录放在项目2的public目录下;

4.然后再项目2的main.js文件中引入我们lib中的common.js并使用它;

复制代码
import indexVue from '../public/lib/indexVue.common.js'
Vue.use(indexVue)

5.再我们的项目2的页面中直接使用它;

复制代码
<template>
  <div class="app-container">
    <index-vue></index-vue>
  </div>
</template>
<script>

export default {
  name: 'WorkProcess',

  data() {
    return {}

  },
}
</script>

<style scoped>

</style>
相关推荐
Wect31 分钟前
LeetCode 39. 组合总和:DFS回溯解法详解
前端·算法·typescript
Wect34 分钟前
LeetCode 46. 全排列:深度解析+代码拆解
前端·算法·typescript
IT_陈寒35 分钟前
Vite 凭什么比 Webpack 快50%?揭秘闪电构建背后的黑科技
前端·人工智能·后端
颜酱36 分钟前
Dijkstra 算法:从 BFS 到带权最短路径
javascript·后端·算法
hi大雄1 小时前
我的 2025 —— 名为《开始的勇气》🌱
前端·年终总结
从文处安1 小时前
「前端何去何从」一直写 Vue ,为何要在 AI 时代去学 React?
前端·react.js
aircrushin2 小时前
OpenClaw“养龙虾”现象的社会技术学分析
前端·后端
明君879972 小时前
#Flutter 的官方Skills技能库
前端·flutter
yuki_uix2 小时前
重新认识 React Hooks:从会用到理解设计
前端·react.js
林太白2 小时前
ref和reactive对比终于学会了
前端