我最近在Symfony中启动了一个新项目,我做了所有here
但这没有帮助。

我第一次在Symfony工作,这是我的第一个项目。我严格按照文档进行操作,并且尝试添加一些CSS,但现在可以使用了。我使用Encore并按文档所述下载Yarn。
下面,我将上传一些代码。看起来不错,但事实并非如此。

html.twig

<!DOCTYPE html>
<html lang="en" xmlns:th="http:thymeleaf.org">

<head>
<title>Events & People</title>
<meta charset="UTF-8">


{% block stylesheets %}
{#{% stylesheets '@AppBundle/public/build/app.css' %}#}
    {{ encore_entry_link_tags('app') }}
    <link src="/build/app.css" rel="stylesheet"/>

{#{% endstylesheets %}#}
{% endblock %}
</head>


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')
// 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 you JavaScript imports CSS.
 */
.addEntry('app', './assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')

// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()

/*
 * FEATURE CONFIG
 *
 * Enable & configure other features below. For a full
 * list of features, see:
 * https://symfony.com/doc/current/frontend.html#adding-more-features
 */
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())

//11111111111
// .enableSassLoader()
//
// // processes files ending in .less
// .enableLessLoader()
//
// // processes files ending in .styl
// .enableStylusLoader()
//11111111111

// enables Sass/SCSS support
//.enableSassLoader()

// uncomment if you use TypeScript
//.enableTypeScriptLoader()

// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();


这是我的文件树的图像:

php - CSS和javascript在Symfony元素中不起作用-LMLPHP

如果正确完成,则应从我的/build/app.css加载文件,但不会加载。

最佳答案

我没有进行深入的搜索,但是一个不好的想法是您的链接标记...

替换(由href替换为src)

<link src="/build/app.css" rel="stylesheet"/>


通过

<link href="/build/app.css" rel="stylesheet"/>

10-07 21:46