Symfony Webpack:从Webpack中找不到入口点文件

时间:2018-11-22 17:48:43

标签: php symfony webpack

安装Webpack Encore之后,相对较新的Symfony 4.1.7项目会引发错误

  

在渲染模板期间引发了异常   (“无法从Webpack中找到入口点文件:该文件   “ ... / public / build / entrypoints.json”不存在。”)

其中模板包括 {{ encore_entry_link_tags('app') }} 启动http://127.0.0.1:8000/

我错过了什么?

$ yarn encore dev
Running webpack ...

 DONE  Compiled successfully in 1974ms

 I  3 files written to public\build
Done in 3.33s.

.../public/build包含

app.css
app.js
manifest.json

本地Symfony版本:

symfony/webpack-encore-bundle       v1.0.0
symfony/webpack-encore-pack         v1.0.3

webpack.config.js:

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

Encore
    // the project directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // the public path used by the web server to access the previous directory
    .setPublicPath('/build')
    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())
    // uncomment to create hashed filenames (e.g. app.abc123.css)
    // .enableVersioning(Encore.isProduction())

    // uncomment to define the assets of the project
    .addEntry('app', './assets/js/app.js')
//     .addEntry('js/app', './assets/js/app.js')
//     .addStyleEntry('css/app')
//     .addStyleEntry('css/app', './assets/css/app.scss')

    // uncomment if you use Sass/SCSS files
    // .enableSassLoader()

    // uncomment for legacy applications that require $/jQuery as a global variable
     .autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();

2 个答案:

答案 0 :(得分:7)

将package.json中@ symfony / webpack-encore的版本约束更新为^ 0.21.0

...
"devDependencies": {
    "@symfony/webpack-encore": "^0.21.0",
...

将.enableSingleRuntimeChunk()添加到您的webpack.config.js

...
.addEntry('app', './assets/js/app.js')
//     .addEntry('js/app', './assets/js/app.js')
//     .addStyleEntry('css/app')
//     .addStyleEntry('css/app', './assets/css/app.scss')
.enableSingleRuntimeChunk()
...

然后运行纱线升级或安装纱线

PS:如果已安装symfony / webpack-encore-bundle,则可以删除symfony / webpack-encore-pack

composer remove symfony/webpack-encore-pack

答案 1 :(得分:0)

万一有人在登台服务器或生产服务器上遇到类似问题:确保资产构建在部署过程中运行。例如,在Heroku上,您需要使用postinstall script

{
    "devDependencies": {
        "@fortawesome/fontawesome-free": "^5.5.0",
        "@symfony/webpack-encore": "^0.22.0",
        "webpack-notifier": "^1.6.0"
    },
    "license": "UNLICENSED",
    "private": true,
    "scripts": {
        "dev-server": "encore dev-server",
        "dev": "encore dev",
        "watch": "encore dev --watch",
        "postinstall": "encore production --progress" // executed during deployment to Heroku
    },
    "dependencies": {
        "bootstrap": "^4.1.3",
        "fontawesome": "^4.7.2",
        "jquery": "^3.3.1",
        "node-sass": "^4.10.0",
        "popper.js": "^1.14.6",
        "sass-loader": "^7.1.0"
    }
}