npm&&无法运行两项任务

时间:2016-07-07 08:30:48

标签: npm

我试图直接使用npm作为我的构建工具。

    {
      "name": "ang-starter",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "jshintConfig": {
        "predef": ["angular"]
      },
      "scripts": {
        "autoprefixer": "postcss -u autoprefixer -r src/assets/css/*",
        "scss": "node-sass --output-style compressed -o src/assets/css src/assets/sass/main.scss",
        "jshint": "jshint src/app/*.js",
        "uglify": "uglifyjs src/app/*.js -o src/assets/js/app.min.js",
        "serve": "browser-sync start --server --files 'src/assets/css/, src/assets/js/*.js, **/*.html, !node_modules/**/*.html'",
        "watch:css": "onchange 'src/assets/sass/*.scss' -- npm run scss",
        "watch:js": "onchange 'src/app/**/*.js' -- npm run jshint && npm run uglify",
        "watch:all": "npm-run-all -p serve watch:css watch:js watch:images",
        "postinstall": "npm run build:all && npm run watch:all"
      },
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "autoprefixer": "^6.3.7",
        "browser-sync": "^2.13.0",
        "jshint": "^2.9.2",
        "node-sass": "^3.8.0",
        "npm-run-all": "^2.3.0",
        "onchange": "^2.5.0",
        "postcss-cli": "^2.5.2",
        "uglify-js": "^2.6.4"
      }
    }

我的文件夹设置就像。

    src
        app
            controllers
            directives
            filters
            services
        assets
            css
            images
            js
            sass
        templates

    index.html

    package.json    

我的问题是关注:js,我可以单独运行jshint和uglify并且它们可以工作但是如果我运行watch:js使用&&运行jshint然后uglify然后uglify没有工作,它在jshint停止。

1 个答案:

答案 0 :(得分:0)

尝试使用npm run watch:js代替npm watch:js

我在angular2中遇到了与npm相同的问题。构建脚本:

"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"

不会工作 - 但这两个命令都是独立运行的。 run为我解决了这个问题。