[toc]
阐明
当初前端开发都是工程化治理, npm、yarn等包管理工具会在源码目录下生产node_modules文件夹;
node_modules文件夹很宏大, 文件数量很多, 有时候心愿挪动到其余地位, 这里提供一种办法;
原理
创立node_modules、package.json和其余的配置文件(如postcss.config.js)的符号链接(symbolic link)
批处理脚本
命名为mknm.bat
放到path门路, 在前端源码根目录执行mknm
@rem 作用:在传入的文件夹下创立一个node_modules的link
@rem 用法: 参数: 一个文件夹的残缺门路, 如果疏忽应用当前目录;
@rem 其余:
@rem 2018/11/08 周四 15:32:59.03
@echo off&SetLocal EnableDelayEdexpansion
rem 传入一个文件夹门路
if "%1" equ "" (
"%~0" "%cd%"
goto :eof
)
echo 以后门路: %cd%
echo;
rem 1. 传入一个文件夹的门路; 2. 在baseDir创立同名的文件夹; 3. 创立link
set dirPath=%~1
set dirName=%~nx1
set baseDir=D:\_node_modules
if not defined dirPath (
echo 参数为空; 应该传入门路
pause&goto :eof
)
rem 创立文件夹; 最终的文件夹的门路是newDir
call :creatDir "!dirName!"
mklink /d "!dirPath!\node_modules" "!newDir!\node_modules"
mklink "!newDir!\package.json" "!dirPath!\package.json"
if exist "!dirPath!\postcss.config.js" (
mklink "!newDir!\postcss.config.js" "!dirPath!\postcss.config.js"
)
set file="!newDir!\readme.txt"
(
echo mklink /d "!dirPath!\node_modules" "!newDir!\node_modules"
echo mklink "!newDir!\package.json" "!dirPath!\package.json"
echo mklink "!newDir!\postcss.config.js" "!dirPath!\postcss.config.js"
) >%file%
echo 实现..........
goto :eof
:creatDir
set "name=%~1"
:A
set newDir=!baseDir!\!name!
if not exist "!newDir!" (
mkdir "!newDir!\node_modules"
goto :eof
) else (
set "name=!name!-1"
goto :A
)
:eof
留神
不保障100%无效, 可能install出错、运行出错, 能够尝试把其余文件(比方vue.config.js)也link一下;
发表回复