【问题标题】:Call a nested package.json script调用嵌套的 package.json 脚本
【发布时间】:2021-05-25 03:18:43
【问题描述】:

所以我有一个 package-scripts 文件夹,其中包含我在 react 环境中构建的所有脚本:

const npsUtils = require('nps-utils')

module.exports = {
  scripts: {
    default: 'react-scripts start',
    build: 'react-scripts build',
    test: 'react-scripts test',
    eject: 'react-scripts eject',
    lint: {
      default: 'eslint ./ --ignore-path .gitignore',
      fix: 'yarn run lint -- --fix',
    },
    format: 'prettier --write "{,!(node_modules)/**/}*.js"',
    validate: npsUtils.concurrent.nps('lint', 'format', 'build'),
  },
}

但是,当我尝试调用 lint 修复脚本时,它总是失败。我的电话yarn start lint:fix 总是失败并给出错误

脚本必须解析为字符串。没有脚本可以 从“lint:fix”解决

那么我该如何调用 lint fix?

【问题讨论】:

    标签: reactjs npm nps


    【解决方案1】:

    你可以这样做:

    scripts: {
      ...
      "lint:default": "eslint ./ --ignore-path .gitignore",
      "lint:fix": "yarn run lint -- --fix",
      ...
    }
    

    并通过以下方式调用它:

    yarn start lint:fix
    

    【讨论】:

      猜你喜欢
      • 2014-06-26
      • 2013-05-10
      • 1970-01-01
      • 2016-04-11
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      相关资源
      最近更新 更多