user3335812
user3335812

Reputation:

NPM environment variables not working in windows?

In my package.json file I'm trying to compile less code using versioning, something like this:

"scripts" {
...
"build:css": "lessc --source-map css/index.less build/$npm_package_name.$npm_package_version.css",
...
}

The problem is that the output files come back as

$npm_package_name.$npm_package_version.css

instead of

my-project.1.0.0.css

I've read that you can do

%npm_package_name%.%npm_package_version%.css

but this hasn't worked for me.

Anyone know why the variables aren't working? Do these variables work at all in Windows? If so, how do I make them work?

Upvotes: 2

Views: 2738

Answers (2)

Mark Woon
Mark Woon

Reputation: 2196

To make it cross-platform, use cross-var:

"scripts" { ... "build:css": "cross-var lessc --source-map css/index.less build/$npm_package_name.$npm_package_version.css", ... }

Upvotes: 2

Burt_Harris
Burt_Harris

Reputation: 6874

This package.json works for me on Windows 10:

{
  "name": "x",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "Unlicense"
}

Note however that the environment variable substitution occurs after its been echoed by NPM, so the output looks like this:

C:\try\x>npm test

> [email protected] test C:\try\x
> echo %npm_package_name%.%npm_package_version%.css

x.1.0.0.css

Upvotes: 0

Related Questions