简体   繁体   English

Symfony Webpack Encore 和公司通用捆绑包

[英]Symfony Webpack Encore with company common bundle

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.这是交易,我们有一个 Symfony “模块”(前 Bundle)公司制造,我们在多个项目中共享。 Atm it is not listed on packagist and we require it with local composer repository paths if that matters. Atm 它没有在 packagist 上列出,如果这很重要,我们需要它与本地作曲家存储库路径。

Inside the shared module we have some css and some js that needs to be included.在共享模块中,我们需要包含一些 css 和一些 js。 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.由于其中一个共享模块(或捆绑,您想调用它)具有引导程序(css 前端工具包),因此模块本身需要它和他的 css。

Inside the shared module we have a JS file "CoreLibrary.js" and we import the required js like this:在共享模块中,我们有一个 JS 文件“CoreLibrary.js”,我们像这样导入所需的 js:

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:然后,在主应用程序中,我们从 app.js 文件中包含公共 js 文件,如下所示:

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.在我们需要的每个 .js 文件中。 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".旁注:不久前我什至不得不关注这个: Symfony 4.1 项目中的 Yarn 和 Webpack Encore 配置,因为我在“yarn watch”期间遇到了错误。

What is the correct way of doing it with company-shared module that requires 3rd party library like bootstrap?使用需要像引导程序这样的第三方库的公司共享模块的正确方法是什么?

For global jquery i have this in main js file对于全局 jquery,我在主 js 文件中有这个

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

Also uncommented line in webpack config about jquery. webpack 配置中关于 jquery 的注释也未注释。

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

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