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

Ous*_*ane 5 heroku symfony npm yarnpkg webpack-encore

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

但是我无法运行

$ yarn run encore production 
Run Code Online (Sandbox Code Playgroud)

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

// composer.json
 "compile": [
     "node_modules/.bin/encore production",
     [•••]
Run Code Online (Sandbox Code Playgroud)

或在 package.json

//package.json

  "scripts": {
    "heroku-postbuild" : "yarn run encore production"
    [•••]
Run Code Online (Sandbox Code Playgroud)

小智 5

在您的 package.json 根文件中:

"scripts": {
    ...
    "heroku-postbuild" : "node_modules/.bin/encore production"
}
Run Code Online (Sandbox Code Playgroud)

它将运行您的 webpack encore 并运行您的其他 npm 模块。

  • 这对我帮助很大。`"heroku-postbuild" : "encore production"` 就够了。 (2认同)

Jav*_*luz 0

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