我刚开始使用 symfony 制作网站。我对此很陌生,但仍然使用互联网和所有文档,我设法了解它的基本工作原理,并且我想出了如何在 symfony 上为我的 css 代码使用资产。我已经用条目配置了我的资产,其他一切似乎都有效。甚至我的公共目录似乎都没问题。现在,当我尝试编写一些 css 时,它似乎没有加载到我的主页上:/。有人可以帮我弄这个吗 ?谢谢你的帮助 !:)这是我的 WEBPACK.CONFIG.JS // directory where compiled assets will be stored .setOutputPath('public/build') // public path used by the web server to access the output path .setPublicPath('/build') // only needed for CDN's or sub-directory deploy //.setManifestKeyPrefix('build/') /* * 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 your JavaScript imports CSS. */ //.addEntry('app', './assets/js/app.js') //.addEntry('page1', './assets/js/page1.js') //.addEntry('page2', './assets/js/page2.js') .addEntry('style', './assets/css/app.css')这是我的 BASE.TWIG.HTML 文件<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>{% block title %}Welcome!{% endblock %}</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> {% block stylesheets %}<link rel="stylesheet" href="{{ asset('/build/css/style.css') }}">{% endblock %} </head> <body> {% block body %}{% endblock %} {% block javascripts %}{% endblock %} </body></html>这是我想应用 CSS 的页面的头部{% extends 'base.html.twig' %}{% block body%}<h1>welcome</h1><img src="" alt="Home pic" class="bckPic"> <!-- About --><h2 class="headTitle">About</h2> <div class="row"> <p class="col">blablablablablabla</p> <img class="col" src="" alt="logo"> </div>
1 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
您的代码似乎是正确的。
尝试改变
`<link rel="stylesheet" href="{{ asset('/build/css/style.css') }}">`
和
{{ encore_entry_link_tags('style') }}
“style” 是 webpack.config.js 中的条目名称 -> .addEntry('style', './assets/css/app.css')
然后在命令行中转到源根文件夹并运行:
yarn install
#for develop env
yarn encore dev
#for prod env
#yarn encore prod
并刷新页面
请参阅:https : //symfony.com/doc/current/frontend/encore/installation.html
- 1 回答
- 0 关注
- 148 浏览
添加回答
举报
0/150
提交
取消