src/**/* 和 'src/**/*' 有什么区别
what's the difference between src/**/* and 'src/**/*'
我想用 nodemon
开始我的项目
"scripts": {
"start": "tsc && node build/index.js",
"watch-server1": "nodemon --watch src/**/* -e ts,tsx --exec ts-node ./src/index.ts",
"watch-server2": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node' ./src/index.ts"
},
但是当我使用 watch-server1
:
(node:6830) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/leonsux/Desktop/Code/home/src/router/index.js:5
export default router;
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1167:16)
at Module._compile (internal/modules/cjs/loader.js:1215:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
at Module.load (internal/modules/cjs/loader.js:1100:32)
at Function.Module._load (internal/modules/cjs/loader.js:962:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at main (/Users/leonsux/Desktop/Code/home/node_modules/ts-node/src/bin.ts:198:14)
at Object.<anonymous> (/Users/leonsux/Desktop/Code/home/node_modules/ts-node/src/bin.ts:288:3)
at Module._compile (internal/modules/cjs/loader.js:1251:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
[nodemon] app crashed - waiting for file changes before starting...
当我使用watch-server2
时,效果很好
那么,src/**/*
和'src/**/*'
有什么区别
未加引号的 shell 字符如 *
将在参数传递给 nodemon
之前由您的 shell(例如 bash)扩展。
在单引号中引用它们将保护它们不被 shell 扩展,因此 nodemon
将作为参数传递文字字符串 src/**/*
。 (它可以为所欲为——大概是扩展通配符本身。)
这会产生很大差异的示例:
scp 'remoteserver:*.txt' .
对战:
scp remoteserver:*.txt .
引用 *
允许 scp 打开到远程服务器的安全连接并查看其中存在的文件。
如果 *
被您的本地 shell 扩展,它只会在您的本地计算机上查找名称类似于“remoteserver:foo.txt”的文件,并且可能会找到 none.
我想用 nodemon
"scripts": {
"start": "tsc && node build/index.js",
"watch-server1": "nodemon --watch src/**/* -e ts,tsx --exec ts-node ./src/index.ts",
"watch-server2": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node' ./src/index.ts"
},
但是当我使用 watch-server1
:
(node:6830) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/leonsux/Desktop/Code/home/src/router/index.js:5
export default router;
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1167:16)
at Module._compile (internal/modules/cjs/loader.js:1215:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
at Module.load (internal/modules/cjs/loader.js:1100:32)
at Function.Module._load (internal/modules/cjs/loader.js:962:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at main (/Users/leonsux/Desktop/Code/home/node_modules/ts-node/src/bin.ts:198:14)
at Object.<anonymous> (/Users/leonsux/Desktop/Code/home/node_modules/ts-node/src/bin.ts:288:3)
at Module._compile (internal/modules/cjs/loader.js:1251:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
[nodemon] app crashed - waiting for file changes before starting...
当我使用watch-server2
时,效果很好
那么,src/**/*
和'src/**/*'
未加引号的 shell 字符如 *
将在参数传递给 nodemon
之前由您的 shell(例如 bash)扩展。
在单引号中引用它们将保护它们不被 shell 扩展,因此 nodemon
将作为参数传递文字字符串 src/**/*
。 (它可以为所欲为——大概是扩展通配符本身。)
这会产生很大差异的示例:
scp 'remoteserver:*.txt' .
对战:
scp remoteserver:*.txt .
引用 *
允许 scp 打开到远程服务器的安全连接并查看其中存在的文件。
如果 *
被您的本地 shell 扩展,它只会在您的本地计算机上查找名称类似于“remoteserver:foo.txt”的文件,并且可能会找到 none.