小智 10
我知道这是一个较旧的问题,但我遇到了同样的问题。我遇到的解决方案是首先创建一个空node_modules文件夹,然后将其与云同步。
同步空文件夹后,我就进入了
OneDrive 设置 ? 选择文件夹
并取消选择node_modules文件夹。
然后当你npm install在项目根文件夹中运行时,OneDrive 会检测到与云中文件夹内容的冲突。它不会同步。
这种方法的缺点是 OneDrive 会产生同步错误,但它似乎很适合我的需要。
OneDrive 不允许按名称排除目录,这不会很快改变:
[OneDrive 对 UserVoice 请求的代表回应:] 现在不是
有些人建议取消选中您不想在 OneDrive 设置中同步的目录,但使用OneDrive Files on-demand就不可能了。
但是,您可以通过在 Node.js 方面进行调整来解决此问题。使node_modules目录成为指向不同位置的文件符号链接:
# Open any place outside OneDrive
cd D:\node_dependencies
# Make a symlink target. After linking, node_modules for your project
# will be installed here
mkdir node_modules_for_my_project
# Open the project directory
cd <the project directory>
# Make a *file* link from node_modules to the newly created directory.
# You will need to delete existing node_modules directory if it exists
cmd /C "mklink node_modules D:\node_dependencies\node_modules_for_my_project"
Run Code Online (Sandbox Code Playgroud)
这里的重要部分是您创建一个文件符号链接,而不是目录。OneDrive 不会识别和同步此符号链接,而 Node.js 将按预期使用它:
在 OneDrive v17.3.7101.1018 和 OneDrive 文件按需启用的情况下进行了测试。
这不是通用的解决方案。这样做的一个缺点是 Explorer、Powershell 和其他工具无法识别node_modules为目录:
但是,基于 Node.js 的代码编辑器可以很好地读取它:
小智 5
我发现最好的解决方案是在 OneDrive 文件夹之外创建一个“本地”文件夹,其中将保存项目并安装所有模块。这是实际的项目。
为了将其同步到 OneDrive,我手动创建一个“并行”文件夹,并使用“RoboCopy”仅复制我想要的内容。然后您可以安排此任务。
要忽略的文件和文件夹名称/通配符是从 .gitignore 文件复制的
解决方案基于几篇文章:
您还可以使用GUI创建要计划的.bat任务文件。microsoft 的 GUI 和ChoEazyCopy GUI 哪个更好
| 归档时间: |
|
| 查看次数: |
12337 次 |
| 最近记录: |