简体   繁体   English

Symfony 4 - Webpack Encore 的一些困难

[英]Symfony 4 - Some difficults with Webpack Encore

I am having a problem using Encore webpack in my Symfony 4 project.我在我的 Symfony 4 项目中使用 Encore webpack 时遇到问题。

I currently have all my files css / js / scss / images in the public folder.我目前在公共文件夹中有我的所有文件 css / js / scss / images。 And in this one I have a sideBar folder that contains folders that contain files themselves:在这个我有一个侧边栏文件夹,其中包含包含文件本身的文件夹:

在此处输入图像描述

And it can happen that in some of my files like the "main.css", at a time, I use other files thanks to the function url ():由于 function url (),我可能会在我的一些文件(如“main.css”)中使用其他文件:

example:例子:

.sidebar-bg.bg1 .sidebar-wrapper {
  background-image: url(../img/bg1.jpg); }

And since this is the first time I really use WebpackEncore, I have difficulties to know what strategy to adopt to be able to gather all this.由于这是我第一次真正使用 WebpackEncore,我很难知道采用什么策略来收集所有这些。

Do I have to create an app.js file in which I will import all the files from my sideBar folder one by one?我是否必须创建一个 app.js 文件,在其中我将从我的 sideBar 文件夹中一一导入所有文件?

You have two possibilities, first one you can import as your said all files in one file "app.js" for example.您有两种可能性,例如,您可以在一个文件“app.js”中导入您所说的所有文件。 This file is your "entry" in your Webpack Encore config file ( https://symfony.com/doc/current/frontend/encore/installation.html )该文件是您在 Webpack Encore 配置文件中的“条目”( https://symfony.com/doc/current/frontend/encore/installation.ZFC35FDC70D5FC69D2569883A822C

The second option is that you can add multiple entries in your Webpack Encore config file (best practice is one by page) and in each one import some of your files when needed:第二个选项是您可以在 Webpack Encore 配置文件中添加多个条目(最佳实践是逐页),并在需要时在每个条目中导入一些文件:

.addEntry('app', './assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM