记录在项目中引用本地的npm包

1、先把需要的包下载下来,以Photo Sphere Viewer 为引用的npm包、项目以shpereRepo为例子

javascript 复制代码
git clone https://github.com/mistic100/Photo-Sphere-Viewer

2、拉下代码后修改之后执行 ./build.sh

build.sh

javascript 复制代码
#!/usr/bin/env bash

yarn run build
targetDir="../shpereRepo/packages/basic/photo-sphere-viewer-dist"
mkdir -p $targetDir/core/dist
mkdir -p $targetDir/markers-plugin/dist
mkdir -p $targetDir/autorotate-plugin/dist

# 拷贝文件到 dist 子文件夹中
cp -rf ./packages/core/dist $targetDir/core
cp -rf ./packages/markers-plugin/dist $targetDir/markers-plugin
cp -rf ./packages/autorotate-plugin/dist $targetDir/autorotate-plugin

3、在shpereRepo 创建photo-sphere-viewer-dist 文件夹

4、在引用包的项目中的package.json修改为本地地址

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/547c156bf06e4a5b90206cef0b87316c.png![在这里插入图片描述](https://file.jishuzhan.net/article/1772811944470777857/dcff8be4f728d0bd9e48cf850c88781f.webp)

5、执行安装 pnpm install

6、运行项目

另也可以用node,把它写入到项目指定文件夹

修改package.json

javascript 复制代码
build": "turbo run build && node copyFolders.js",

附copyFolders.js

javascript 复制代码
const fs = require('fs');
const path = require('path');

const autorotatePluginPath = './packages/autorotate-plugin/dist';
const markersPluginPath = './packages/markers-plugin/dist';
const corePath = './packages/core/dist';
const targetDirectory = '../shpereRepo/packages/basic/photo-sphere-viewer-dist';

// 创建目标文件夹
if (!fs.existsSync(targetDirectory)) {
  fs.mkdirSync(targetDirectory, { recursive: true });
}

// 拷贝文件夹函数
function copyFolder(sourceFolderPath, targetFolderName) {
  const targetFolderPath = path.join(targetDirectory, targetFolderName);
  fs.mkdirSync(targetFolderPath, { recursive: true });

  const files = fs.readdirSync(sourceFolderPath);
  files.forEach(file => {
    const sourceFilePath = path.join(sourceFolderPath, file);
    const targetFilePath = path.join(targetFolderPath, file);
    fs.copyFileSync(sourceFilePath, targetFilePath);
    console.log(`${sourceFilePath} 文件拷贝完成!`);
  });

  console.log(`${sourceFolderPath} 文件夹拷贝完成!`);
}

// 拷贝指定文件夹到目标位置
copyFolder(autorotatePluginPath, 'autorotate-plugin/dist');
copyFolder(markersPluginPath, 'markers-plugin/dist');
copyFolder(corePath, 'core/dist');
相关推荐
光影少年2 分钟前
vue3.0性能提升主要通过那几方面体现的?
前端·vue.js
小磊哥er15 分钟前
【前端工程化】前端开发中的这些设计规范你知道吗
前端
江城开朗的豌豆15 分钟前
路由守卫:你的Vue路由‘保安’,全局把关还是局部盯梢?
前端·javascript·vue.js
Jinxiansen021123 分钟前
Vue 3 响应式核心源码详解(基于 @vue/reactivity)
前端·javascript·vue.js
OEC小胖胖5 小时前
去中心化身份:2025年Web3身份验证系统开发实践
前端·web3·去中心化·区块链
vvilkim6 小时前
Electron 进程间通信(IPC)深度优化指南
前端·javascript·electron
ai小鬼头8 小时前
百度秒搭发布:无代码编程如何让普通人轻松打造AI应用?
前端·后端·github
漂流瓶jz8 小时前
清除浮动/避开margin折叠:前端CSS中BFC的特点与限制
前端·css·面试
前端 贾公子8 小时前
在移动端使用 Tailwind CSS (uniapp)
前端·uni-app
散步去海边8 小时前
Cursor 进阶使用教程
前端·ai编程·cursor