我有多个package.json
文件脚本命令的ParcelJS项目。
"scripts": {
"parcel": "./node_modules/@mms/parcel-bundler/bin/cli.js","start": "parcel templates/layouts/index.pug","start:news": "parcel templates/layouts/news.pug","start:news-inner": "parcel templates/layouts/news-inner.pug",more and more commads here...
}
上面的package.json
文件可以正常工作,但是随着项目的发展,它变得越来越大,越来越难以阅读。
因此,我想通过删除所有package.json
页面名称来压缩:postfix
脚本块,如果没有指定页面,则将必要的页面名称作为NPM自变量传递给NPM参数,并使用备用后备页面名称。
预期代码示例:
"scripts": {
"parcel": "./node_modules/@mms/parcel-bundler/bin/cli.js","start": "parcel templates/layouts/\"$1 || index\".pug"
}
当然,上面的示例不起作用,因为它存在语法问题,因此作为第一步,我尝试了下面的更简单的代码,并且它也不起作用,我也不知道为什么。
"scripts": {
"parcel": "./node_modules/@mms/parcel-bundler/bin/cli.js","start": "parcel templates/layouts/\"$1\".pug"
}
以上脚本运行的终端结果:
$ yarn start index
yarn run v1.19.1
$ parcel templates/layouts/"${1}".pug index
Server running at http://localhost:1234
? No entries found.
error Command failed with exit code 1.
您能帮我修复此NPM脚本吗?