Linked Questions

Popular Questions

Run Grunt Task in postinstall lifecycle - NPM

Asked by At

We have a list of jQuery UI components in the GIT repository. User can include the entire bundle if they want. In case if the user wishes include specific component alone into their project, the user can set an environment variable "component" mentioning the component they would like to include. Depending on its value I would like to execute a grunt task with the value provided. The package.json for my package is as follows. I want to do like this because I don't want to maintain a separate GIT repository for each of the components as the maintenance is very difficult.

{
  "name": "<package-name>",
  "version": "3.0.24",
  "description": "<value>",
  "main": "<value>",
  "scripts": {
    "postinstall": "cross-var grunt --component=$npm_config_component",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "<value>"
  },
  "keywords": [
    "jquery-plugin",
    "ecosystem:jquery"
  ],
  "author": "<value>",
  "license": "ISC",
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-cli": "^1.2.0",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-cssmin": "^2.2.0",
    "grunt-contrib-sass": "^1.0.0",
    "grunt-contrib-uglify": "^3.0.1"
  }
}

But the problem is after publishing If i provide npm install "package-name", I get the following error

> cross-var grunt --component=$npm_config_component

>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?
>> Local Npm module "grunt-contrib-sass" not found. Is it installed?
>> Local Npm module "grunt-contrib-cssmin" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
Warning: Task "concat" not found. Use --force to continue.

Aborted due to warnings.

I tried moving the devDependencies to dependencies and tried installing the package again. But nothing seem to work. I also tried putting npm install in the preinstall of the my package.json that is infinitely executing the same line again and again when I provide npm install <package-name>

Related Questions