Symfony 4-在Heroku上部署时找不到Webpack静态文件

时间:2018-08-14 14:21:50

标签: symfony heroku webpack

我试图在Heroku上部署我的Symfony 4应用程序,并且可以运行,但是找不到由Webpack Encore管理的css和js文件(404),我不明白为什么。

这是我的文件配置:

webpack.config.js

var Encore = require('@symfony/webpack-encore');

const Path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const root = Path.resolve(__dirname, '');

Encore
    .setOutputPath(Path.resolve(root, 'public/build'))
    .setPublicPath('/build/')
    .setManifestKeyPrefix('/build/')

    .cleanupOutputBeforeBuild()
    .addEntry('js/app', Path.resolve(root, 'assets/js/app.js'))
    .addStyleEntry('css/app', Path.resolve(root, 'assets/css/app.css'))
    .addStyleEntry('css/login', Path.resolve(root, 'assets/css/login.css'))
    .addPlugin(new CopyWebpackPlugin([
        { from: Path.resolve(root, 'assets/images'), to: Path.resolve(root, 'public/build/images') }
    ]))
;

module.exports = Encore.getWebpackConfig();

package.json

"devDependencies": {
    "@symfony/webpack-encore": "^0.19.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
    "dev-server": "encore dev-server",
    "dev": "encore dev",
    "watch": "encore dev --watch",
    "build": "encore production",
    "heroku-postbuild": "node_modules/.bin/encore production"
},
"dependencies": {
    "copy-webpack-plugin": "^4.5.2",
    "path": "^0.12.7"
}

apache_app.conf在我的根项目中

DirectoryIndex index.php
Options FollowSymlinks

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

Procfile

web: vendor/bin/heroku-php-apache2 -C apache_app.conf public/

在我的树枝模板中

<script src="{{ asset('build/js/app.js') }}"></script>

在本地一切正常,但是在Heroku上部署时,找不到css和js文件。 谢谢您的帮助!

0 个答案:

没有答案