在实时服务器上找不到yarn encore app.js文件

时间:2018-12-04 13:33:23

标签: symfony webpack yarnpkg webpack-encore

我的app.js在本地运行良好,但是在实时网站上运行时却找不到404。该文件在/ web / js文件夹中编译。

    {% block javascripts %}
     <script src="{{ asset('js/runtime.js')}}"></script>
     <script src="{{ asset('js/app.js')}}"></script>
    {% endblock %}

note框架是symfony 2.8

webpack.config.js看起来像这样,不确定setPublic路径是否应如下所示。

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

  Encore
 // directory where compiled assets will be stored
 .setOutputPath('web/js/')
 // public path used by the web server to access the output path
 .setPublicPath('/js')


/*
 * ENTRY CONFIG
 *
 * Add 1 entry for each "page" of your app
 * (including one that's included on every page - e.g. "app")
 *
 * Each entry will result in one JavaScript file (e.g. app.js)
 * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
 */
 .addEntry('app', './app/Resources/assets/js/app.js')

.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())

.autoProvidejQuery()

module.exports = Encore.getWebpackConfig();

是否需要runtime.js,并且似乎需要在本地使用,但不确定使用

1 个答案:

答案 0 :(得分:0)

只需将资产文件放入Web文件夹。 asic webpack.config.js应该看起来像这样:

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

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')

    .addEntry('app', './assets/js/app.js');

然后要构建资产,请运行以下命令:

yarn encore dev

成功编译后,您可以在树枝模板中使用已编译的资产。

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