记录在项目中引用本地的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');
相关推荐
qq_5470261792 小时前
Flowable 工作流引擎
java·服务器·前端
刘逸潇20052 小时前
CSS基础语法
前端·css
吃饺子不吃馅3 小时前
[开源] 从零到一打造在线 PPT 编辑器:React + Zustand + Zundo
前端·svg·图形学
小马哥编程4 小时前
【软考架构】案例分析-Web应用设计(应用服务器概念)
前端·架构
鱼与宇4 小时前
苍穹外卖-VUE
前端·javascript·vue.js
啃火龙果的兔子4 小时前
前端直接渲染Markdown
前端
z-robot4 小时前
Nginx 配置代理
前端
用户47949283569155 小时前
Safari 中文输入法的诡异 Bug:为什么输入 @ 会变成 @@? ## 开头 做 @ 提及功能的时候,测试同学用 Safari 测出了个奇怪的问题
前端·javascript·浏览器
没有故事、有酒5 小时前
Ajax介绍
前端·ajax·okhttp
朝新_5 小时前
【SpringMVC】详解用户登录前后端交互流程:AJAX 异步通信与 Session 机制实战
前端·笔记·spring·ajax·交互·javaee