symfony - Symfony Webpack Encore:从 Bundle 导入 .js
问题描述
使用 Symfony,我创建了一个包。此捆绑包已正确导入/vendor
. 此捆绑包有两个公共文件:
/MyBundle/Resources/Public/css/mybundle.scss
/MyBundle/Resources/Public/js/mybundle.js
如何使用 Wepack Encore 在我的主项目中导入这些文件?
目前我正在做:
在assets/js/app.js
:
导入“../../vendor/gaylordp/mybundle/Resources/public/js/mybundle.js”;
在assets/css/app.scss
:
@import "../../vendor/gaylordp/mybundle/Resources/public/css/mybundle.scss";
但是我认为这不是理想的解决方案……您还有其他想法吗?
解决方案
在我看来,您有两种解决方案:
像@hoover_D 所说的那样做。在 webpack.config.js 中添加两个条目。
// for the js .addEntry('js/mybundle', './vendor/.../mybundle.js') // for the scss .addStyleEntry('css/mybundle', './vendor/.../css/mybundle.scss')
如果多个文件需要你的包的 js 代码,你可以使用
createSharedEntry
. 文档在这里。// for the js .createSharedEntry('js/mybundle', './vendor/.../mybundle.js') // for the scss .addStyleEntry('css/mybundle', './vendor/.../css/mybundle.scss')
推荐阅读
- java - grpc v1.34.1 的客户端负载平衡,nameResolverFactory 已弃用
- post - 如果没有请求使用 jmeter 显示这些值作为响应,我们如何捕获 access_token、session_id 值?
- javascript - expect(received).toEqual(expected) // npm 测试中的深度相等,更改行时的字符串添加一个“.” 最后在返回的字符串中
- ruby-on-rails - Ransack:Rails 6 > PG::UndefinedTable: 错误定义了自定义外键
- java - Spring Security、Basic Auth 和 Anyonymous
- typescript - 吸气剂没有被正确调用
- symfony - 安全具有角色与 is_granted
- sed - 用 sed 替换多个文件中的一个事件
- php - 我无法获得简单的 reCaptcha v2 工作响应
- angular - 有条件地改变组件的动画