dominique-mueller/hugo-installer

Option to only install hugo on npm --production

sean-au opened this issue · 4 comments

My current issue is I have set up my hugo projects so that dependencies which are not required on netlify (e.g. linting or formatting or hugo) are installed as devDependencies. This way my netlify build is sped up.

The problem is that I have hugo-installer set up as a postinstall script and netlify tried to run it, forcing me to have hugo-installer installed as a normal dependency. (netlify is configured to pass the --production parameter)

I have looked into disabling postinstall on production and I cant find a clean solution, without adding another js script to the project.

Would it be easier to include this script in hugo-installer and provide the option e.g. --development so that if hugo-installer is run in the production environment (which only happens if the user specifies this environment) it will exit without running any code.

I haven't had the chance yet to use Netflity, but I understand that you want to simulate Hugo being a dependency instead of a devDependency, which is something npm doesn't support out of the box for postinstall scripts.

I don't think adding this feature makes sense in the context of hugo-installer, I instead see it as a separate concern that should be handled within the npm script itself.

A quick research brought me to npm packages like if-env or per-env, have you tried using one of those as a solution?

Any luck? :)

Yes

There is a npm package called if-env which allows you to only run the hugo postinstall on development (Which is the default environment).

On the other hand, only the initial netlify build is slowed down, everything is cached for subsequent builds