把一个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>
相关推荐
徐小夕13 分钟前
我用 AI 撸了个开源"万能预览器":浏览器直接打开 Office、CAD 和 3D 模型
前端·vue.js·github
小码哥_常28 分钟前
Flutter Android 延迟加载代码指南:提升应用性能的关键
前端
这是个栗子1 小时前
TypeScript(三)
前端·javascript·typescript·react
kvo7f2JTy1 小时前
基于机器学习算法的web入侵检测系统设计与实现
前端·算法·机器学习
北风toto1 小时前
前端CSS样式详细笔记
前端·css·笔记
nanfeiyan1 小时前
git commit
前端
前端精髓3 小时前
移除 Effect 依赖
前端·javascript·react.js
码云之上4 小时前
从一个截图函数到一个 npm 包——pdf-snapshot 的诞生记
前端·node.js·github
码事漫谈4 小时前
AI提效,到底能强到什么程度?
前端·后端
IT_陈寒4 小时前
React hooks依赖数组这个坑差点把我埋了
前端·人工智能·后端