NPM构建脚本不运行

时间:2017-02-23 16:37:02

标签: node.js npm babel

我试图在我的项目中运行babel作为构建步骤,但它似乎无法正常工作。

我的package.json看起来像这样:

{
  "name": "module-name",
  "version": "1.0.0",
  "description": "My Module",
  "main": "build/index.js",
  "scripts": {
    "test": "karma start",
    "build": "./node_modules/.bin/babel src -d build"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.23.0",
    "babel-preset-env": "^1.1.8"
  }
}

.babelrc位于同一目录中,如下所示:

{
  "presets": ["env"]
}

命令npm test正常工作,并且Karma测试运行。但是当我使用npm build --verbose时,我只得到以下输出:

npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\Peter\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'build',
npm verb cli   '--verbose' ]
npm info using npm@3.10.2
npm info using node@v6.9.3
npm verb exit [ 0, true ]
npm info ok

但是Babel命令没有运行,并且没有创建构建目录。但是,直接从命令行运行命令./node_modules/.bin/babel src -d build可以很好地工作。

可能导致问题的任何想法?

1 个答案:

答案 0 :(得分:3)

npm testbuilt in npm command,但您的build命令未内置。

对于内置的npm命令,您需要run

npm run build