V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Yukee798

请教一下 npm scripts 传参问题

  •  
  •   Yukee798 · Feb 8, 2022 · 2010 views
    This topic created in 1552 days ago, the information mentioned may be changed or developed.

    我的 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 replies    2022-02-08 19:30:43 +08:00
    VagabondH
        1
    VagabondH  
       Feb 8, 2022   ❤️ 1
    ``` json
    "scripts": {
    "ttt": "node a.js ${npm_config_type} && node b.js ${npm_config_type}"
    }
    ```
    ```
    npm run ttt --type=button
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2900 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:24 · PVG 19:24 · LAX 04:24 · JFK 07:24
    ♥ Do have faith in what you're doing.