我已经在4.3 Symfony应用程序上安装并配置了webpack encore。 CSS和JS生成,路径看起来不错,但是php在这些文件上返回404错误。
它可以在另一个应用程序中运行,但无法确定问题出在哪里
我将文件放在assets/css
和asset/js
中。
当我运行yarn run encore dev
时,文件已正确复制到public/build/css
和public/build/js
这是输出:
4 files written to public/build
Entrypoint js/app = js/app.css js/app.js
Entrypoint css/cover = css/cover.css
这是我的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')
// the public path you will use in Symfony's asset() function - e.g. asset('build/some_file.js')
.setManifestKeyPrefix('build/')
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
// the following line enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
// uncomment to define the assets of the project
.addEntry('js/app', './assets/js/app.js')
.addStyleEntry('css/cover', './assets/css/cover.css')
;
module.exports = Encore.getWebpackConfig();
我在base.html.twig中调用文件的方式:
{{ encore_entry_link_tags('css/cover') }}
和
{{ encore_entry_script_tags('js/app') }}
还有我的webpack_encore.yaml
webpack_encore:
# The path where Encore is building the assets.
# This should match Encore.setOutputPath() in webpack.config.js.
output_path: '%kernel.project_dir%/public/build'
我希望我哥哥的控制台停止显示
GET https://louboulangerie.fr/build/css/cover.css net::ERR_ABORTED 404 (Not Found)
谢谢
编辑:经过几天的搜索,我发现如果在我的vhost中禁用对https的重写规则,一切都很好。关于如何进行的任何想法?
答案 0 :(得分:0)
最有可能的问题是条目名称。
更改此内容:
.addEntry('js/app', './assets/js/app.js')
.addStyleEntry('css/cover', './assets/css/cover.css')
对此:
.addEntry('app', './assets/js/app.js')
.addStyleEntry('cover', './assets/css/cover.css')
然后像这样导入您的资产:
{{ encore_entry_link_tags('cover') }}
{{ encore_entry_script_tags('app') }}
此外,除非您确实需要,否则不需要添加特殊的样式条目。
这样做会得到相同的结果:
webpack.config.js
.addEntry('app', './assets/js/app.js')
app.js
// I prefer to use import instead of require
import "../css/cover.scss";
base.html.twig
<head>
{{ encore_entry_link_tags('app') }}
</head>
<body>
{{ encore_entry_script_tags('app') }}
</body>
答案 1 :(得分:0)
嗨,我无法发表评论,所以我想写一个答案。
几个月前,我had the same problem。 我不像你那样在树枝里。我所做的就像 例如:
<link rel="stylesheet" href="{{ asset("build/app.css") }}"/>
为我工作。也许尝试这样做可以为您服务?