1

We rename our assets directory on every single git push to handle browser caching issues. This mean that we store a random variable in a config.json file in our project.

I'm trying to move from gulp to npm as a build process, and therefore need to access this stored variable somehow from within the package.json file.

How would I go about such a task, and is it even possible?

"scripts": {
"build-offers": "uglifyjs src/pages/offers/*.js -mc > [HERE I NEED TO PREFIX THE OUTPUT FOLDER USING THE config.json FILE CONTENT] assets/offers.js",
"offers": "npm run build-offers"
},

1 Answer 1

1

You can acces environment variables in your scripts, but i think, that it isn't possible to read such variables from an other file with pure package scripts. Here is a way, you could do it within your package.json.

"config": {
  "prefix": "prefix"
},
"scripts": {
  "build-offers": "uglifyjs src/pages/offers/*.js -mc > %npm_package_config_prefix% assets/offers.js",
  ...
}

NOTE: The above version only works under windows.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.