如何使用Webpack Encore在Heroku上编译资产?

时间:2017-10-10 16:40:36

标签: symfony heroku npm yarnpkg webpack-encore

我在我的Symfony heroku应用程序中添加了一个heroku / nodejs buildpack,我可以安装我的纱线依赖项。

但是我无法运行

$ yarn run encore production 

我是否总是有同样的错误Command "encore" not found我是否在composer.json中运行命令:

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

或在package.json

//package.json

  "scripts": {
    "heroku-postbuild" : "yarn run encore production"
    [•••]

3 个答案:

答案 0 :(得分:3)

在package.json根文件中:

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

它将运行您的Webpack Encore和其他npm模块。

答案 1 :(得分:0)

我总是以cd my-project/ && ./node_modules/.bin/encore ...运行Encore命令这对您有用吗?

答案 2 :(得分:0)

对于来到这里的任何人,您首先需要按照this question将节点buildpack添加到您的应用中。

确保在 之前添加节点buildpack。

然后,将"node_modules/.bin/encore production"添加到编译中(如问题所示)。

最后,如评论所述,不要忘记将devDependencies中的Webpack依赖项从dependencies更改为package.json