记录在项目中引用本地的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');
相关推荐
阿山同学.8 分钟前
AWS 亚马逊 S3存储桶直传 前端demo 复制即可使用
前端·javascript·aws
Jolyne_17 分钟前
grid 实现完美的水平铺满、间隔一致的自适应布局
前端·css
西洼工作室21 分钟前
【解决导航栏字体图标渲染导致文本闪烁问题】采用腾讯视频的解决方案
前端·css·css3
WindrunnerMax28 分钟前
从零实现富文本编辑器#5-编辑器选区模型的状态结构表达
前端·架构·github
CodeSheep34 分钟前
宇树科技,改名了!
前端·后端·程序员
Hilaku41 分钟前
为什么我们用了 Vite 还是构建慢?——真正的优化在这几步
前端·javascript·vite
XI锐真的烦42 分钟前
横向对比npm和yarn
前端·npm·node.js
国家不保护废物42 分钟前
🧩 React 组件化进阶:像乐高大师一样搭建你的应用世界!
前端·react.js·ai编程
TimelessHaze1 小时前
从"切图崽"到前端工程师:React 到底是个啥?🚀
前端·react.js·ai编程
站在风口的猪11081 小时前
《前端面试题:CSS的display属性》
前端·css·html·css3·html5