Home > Back-end >  Check file exists before launch it in webpack npm scripts
Check file exists before launch it in webpack npm scripts

Time:09-24

I have a package.json like this:

...
  "scripts": {
    "dev": "webpack --config webpack.dev.config.js --mode development --progress --colors",
    "postdev": "if (Test-Path \"./postdev.sh\" ) { echo \"file exists\"; ./postdev.sh }"
  },
...

How can I check if file "postdev.sh" exists and then launch it in NPM-scripts section? I run that command in the terminal and it goes correctly, but if I try to launch that npm-script it says "Unexpected appearance: "./postdev.sh"."

CodePudding user response:

on macos or linux try this one for postdev:

"postdev": "test -f ./postdev.sh && echo 'file exisits' && ./postdev.sh",

CodePudding user response:

Finnally found a solution (maybe it works only on Windows, but it is enough for me):

"postdev": "if exist postdev.sh ( postdev.sh )",
  • Related