Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile assets on Heroku with Webpack Encore?

I added a the heroku/nodejs buildpack to my Symfony heroku app, and I am able to install my yarn dependencies.

However I am not able to run

$ yarn run encore production 

I always have the same error Command "encore" not found whether I run the command in composer.json :

// composer.json
 "compile": [
     "node_modules/.bin/encore production",
     [•••]

or in package.json

//package.json

  "scripts": {
    "heroku-postbuild" : "yarn run encore production"
    [•••]
like image 489
Ousmane Avatar asked Oct 10 '17 16:10

Ousmane


2 Answers

In your package.json root file :

"scripts": {
    ...
    "heroku-postbuild" : "node_modules/.bin/encore production"
}

It will run your webpack encore and running your others npm modules.

like image 60
ylaakel Avatar answered Oct 08 '22 23:10

ylaakel


To anyone coming here, you'll first need to add the node buildpack to your app, as per this question.

Make sure to add the node buildpack before the php one.

Then, add "node_modules/.bin/encore production" to your compile (as shown in the question).

Finally, as written in comment, don't forget to change webpack dependencies from devDependencies to dependencies in your package.json.

like image 1
Jonathan Simonney Avatar answered Oct 08 '22 21:10

Jonathan Simonney