V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Yukee798
V2EX  ›  前端开发

请教一下 npm scripts 传参问题

  •  
  •   Yukee798 · 2022-02-08 16:43:59 +08:00 · 1071 次点击
    这是一个创建于 805 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我的 npm 脚本:

    "scripts:" {
      "init-component": "node ./scripts/init-component.js && node ./scripts/init-demo.js"
    }
    

    执行命令行:

    $ npm run init-component -- button
    # 等价于 node ./scripts/init-component.js && node ./scripts/init-demo.js "button"
    

    这样只对 ./scripts/init-demo.js 脚本传入了参数 "button"。

    现在我想只使用下面的命令:

    $ npm run init-component -- button
    

    同时给 ./scripts/init-component.js./scripts/init-demo.js 两个脚本都传入相同参数,应该怎么做呢?

    1 条回复    2022-02-08 19:30:43 +08:00
    VagabondH
        1
    VagabondH  
       2022-02-08 19:30:43 +08:00   ❤️ 1
    ``` json
    "scripts": {
    "ttt": "node a.js ${npm_config_type} && node b.js ${npm_config_type}"
    }
    ```
    ```
    npm run ttt --type=button
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1027 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:41 · PVG 03:41 · LAX 12:41 · JFK 15:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.