chrisgo's avatar

npm run prod

Hi,

Have a "standard" Laravel app that run npm run prod when I do a release.

So my workflow is

Dev: Macbook running Vagrant, using npm run dev for assets.

  • using gitlab.com private repo for source control

I am using fabric (fabfile.org) to ssh into my PROD server (DigitalOcean Debian 9), do a git pull and rsync into nginx. The last step of fabric is to do a

npm run prod

At this point, it takes about 10 minutes for it to do

npm rebuild node-sass
[..................] - : info using [email protected]
... (about 20 lines of this)
> [email protected] install /var/www/projectname/node_modules/node-sass
> node scripts/install.js

Cached binary found at /home/projectdir/.npm/node-sass/4.7.2/linux-x64-48_binding.node

> [email protected] postinstall /var/www/projectname/node_modules/node-sass
> node scripts/build.js

Binary found at /var/www/projectname/node_modules/node-sass/vendor/linux-x64-48/binding.node
Testing binary
Binary is fine
[email protected] /var/www/projectname/node_modules/node-sass

npm run prod
[..................] - : info using [email protected]
[..................] - : info using [email protected]

> @ prod /var/www/projectname
> npm run production

[..................] - : info using [email protected]
[..................] - : info using [email protected]

> @ production /var/www/harness
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

95% emitting

 DONE  Compiled successfully in 102342ms
...

(output with the asset table)

php artisan view:clear

Question: How do I change my workflow so this does not run on every server every time I release code?

I have tried to pre-compile the node-sass on my Mac but it seems like that is not possible because my servers are running Linux (Debian 9).

So if I have 10 load balanced servers, how do I run this once (somewhere) and have the servers pull them down with the npm run prod so it doesn't take 10 minutes per server to do a push to PROD

Is CI the answer?

Thank you

0 likes
2 replies
bobbybouwmann's avatar
Level 88

CI is not your answer, but could be helpful. What you do right now is really good. You shouldn't compile your stuff locally and push that in your repository when pulling it. Your server is capable enough to compile everything down and run it.

However you have a lot of servers running and letting all of them compile the assets is a waste of time. This would be fine with one or two servers, but with more it's ideal!

The best solution for this is using some kind of CDN. So another website or domain that will serve your files. This way you only have to compile them once and your other servers can then pull the data from there.

You can Google around on how to do this in Laravel. There are even packages for this that connect with third-party CDN companies with an API so your assets are always available.

Another solution would be to use containers. With containers you can work locally with the same system and assets as you would on production. Your local development container can even be deployed to productie and would work just fine ;)

1 like
chrisgo's avatar

Hi, the CDN is a great idea! You are using it like source control but better since it actually serves the assets even more efficiently than on your own server. Thanks man!

1 like

Please or to participate in this conversation.