记录在项目中引用本地的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');
相关推荐
宁&沉沦3 小时前
Chrome 扩展 Manifest 字段版本支持一览(全量)
前端·后端·编辑器
乖孩子3 小时前
Service Worker + IndexedDB 实践
前端
浮生望3 小时前
BFF架构实战:用Express+SSE为Vue3搭建安全的流式对话中间层
前端
先吃饱再说4 小时前
React 组件通信:从 Props 单向传递到自定义事件
前端·react.js·前端框架
swipe4 小时前
05|(前端转后全栈)不手写一堆 SQL,后端怎么操作数据库?MyBatis-Plus 入门
前端·后端·全栈
swipe4 小时前
04|(前端转后全栈)前端状态为什么不够用?从页面数据到 MySQL 持久化
前端·后端·全栈
橘子星4 小时前
别光看教程!手把手拆解 React Todo 项目,一文吃透 5 个核心概念
前端·javascript
大白要努力!4 小时前
纯前端实现 PDF 加水印工具 —— 零后端、支持中文、实时预览
前端·pdf·html
石小石Orz4 小时前
TRAE SOLO实战:实现一个桌面3D助手
前端·人工智能
蜡台4 小时前
使用 uni-popup 实现数据选择器Data-Picker
前端·javascript·html·uniapp·uni-popup·data-picker