Symfony WebPack与公司Common Bundle一起

发布于 2025-02-08 05:30:47 字数 1085 浏览 3 评论 0原文

可能还有一些关于如何处理这种情况的文档,但我什至不知道如何寻找它。

这是交易,我们有一个Symfony“模块”(Ex Bundle)公司制造,我们在多个项目中共享。 ATM它没有在Packagist上列出,如果这很重要,我们需要使用本地作曲家存储库路径。

在共享模块中,我们有一些CSS和一些JS需要包括在内。由于这些共享模块之一(或捆绑包,您想称呼它)具有bootstrap(CSS前端工具包),因此模块本身需要与他的CSS一起使用。

在共享模块中,我们有一个JS文件“ coreLibrary.js”,我们会导入这样的JS:

import $ from 'jquery';
import 'bootstrap';
export class CoreLibrary {
    ... more code
}

然后,在主应用程序中,我们在app.js file中包含了这样的常见JS文件

import { CoreLibrary } from '../public/bundles/thebundlename/js/CoreLibrary';

:是理想的,除此之外,我们必须

import $ from 'jquery';
import 'bootstrap';
import { CoreLibrary } from '../public/bundles/thebundlename/js/CoreLibrary';

在所需的每个.js文件中重复。这是一个很大的负担,我无法相信,没有更好的方法对此做出更好的选择。

旁注:不久前我什至不得不遵循这个: yarn and webpack encore encore encore encore in Symfony 4.1项目4.1项目4.1项目因为我在“纱线手表”中遇到了错误。

使用需要第三方图书馆(如Bootstrap)的公司共享模块进行操作的正确方法是什么?

There maybe some documentation out there on how to deal with this situation but i don't even know how to look for it.

Here's the deal, we have a Symfony "module" (ex Bundle) company-made that we share across multiple projects. Atm it is not listed on packagist and we require it with local composer repository paths if that matters.

Inside the shared module we have some css and some js that needs to be included. Since one of those shared-module (or bundle, w/e you want to call it) has bootstrap (the css frontend toolkit) the module itself requires it together with his css.

Inside the shared module we have a JS file "CoreLibrary.js" and we import the required js like this:

import $ from 'jquery';
import 'bootstrap';
export class CoreLibrary {
    ... more code
}

Then, inside the main application we include the common js file from the app.js file like this:

import { CoreLibrary } from '../public/bundles/thebundlename/js/CoreLibrary';

That doesn't seem to be ideal, and beside that, with encore we have to repeat

import $ from 'jquery';
import 'bootstrap';
import { CoreLibrary } from '../public/bundles/thebundlename/js/CoreLibrary';

In every .js file we need. That's so much of a burden that I can't belive there are no better ways do to that.

Sidenote: not so long ago i had to even follow this one:
Yarn and Webpack Encore configuration in Symfony 4.1 project because i was getting error during "yarn watch".

What is the correct way of doing it with company-shared module that requires 3rd party library like bootstrap?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们的影子 2025-02-15 05:30:47

对于全局jQuery,我在主JS文件中也有此内容,

const $ = require('jquery');
global.$ = global.jQuery = $;

在WebPack Config中也没有按照jQuery的限制。

For global jquery i have this in main js file

const $ = require('jquery');
global.$ = global.jQuery = $;

Also uncommented line in webpack config about jquery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文