maba/webpack-migration-bundle
Composer 安装命令:
composer require maba/webpack-migration-bundle
包简介
Bundle to Help Migrating From Assetic to Webpack
README 文档
README
Bundle to help integrating from assetic to webpack.
It uses maba/webpack-bundle and symfony/assetic-bundle as dependencies.
It creates and modifies files in your repository. This means that it is not meant to be run in production - install it, use it and remove it from your project. Always keep sure to use version system like git and have no uncommitted changes as you might loose your stuff.
What is webpack and why to migrate from assetic?
Webpack is module bundler and CommonJS / AMD dependency manager.
For me, it replaces both grunt/gulp and RequireJS.
See what is webpack? and it's documentation for more information.
For comparison with assetic and alternative webpack-based solutions, see maba/webpack-bundle.
What does this bundle do?
- Finds assetic nodes (
stylesheetsandjavascriptsnodes) in your twig templates. - Dumps
jsfiles representing bundled assets. - Replaces them with
webpack_assetfunction with reference to dumped file. - Dumps configured named assets inside
config.yml.
twig-template-modification-bundle is used for replacing the twig templates themselves.
Worth to note that it does support assetic variables, but as the result is usable, it's not really manageable in the long scale. Please see other means to accomplish this with conditional loading from the javascript itself. See symfony-webpack-angular-demo for an example how this could be done with locales.
Also worth to note that it ignores images assetic nodes and other nodes with unrecognised filters.
You can configure ignored filters in config.yml by providing maba_webpack_migration.ignored_filters parameter.
By default, these filters are ignored:
- cssrewrite
- less
- lessphp
- scssphp
- sassphp
- jsqueeze
- uglifyjs
- uglifyjs2
- uglifycss
- yui_css
- yui_js
They are ignored, as js and css files are minified by default on production,
and SCSS and Less files work out of the box.
Assumption is made that you use correct extension for your file types (.less for Less files etc.)
Installation and Usage
composer require maba/webpack-migration-bundle
Inside AppKernel:
new Maba\Bundle\WebpackBundle\MabaWebpackBundle(), // if you don't have it already new Maba\Bundle\WebpackBundle\MabaTwigTemplateModificationBundle(), // dependency new Maba\Bundle\WebpackBundle\MabaWebpackMigrationBundle(),
Setup files for webpack bundle (see maba/webpack-bundle for more information what this does):
app/console maba:webpack:setup
Configure webpack to extract CSS into separate files. This is needed for stylesheets tags to work.
maba_webpack: config: parameters: extract_css: true
Install npm dependencies used by WebpackMigrationBundle which are not installed by default in WebpackBundle:
npm install imports-loader exports-loader expose-loader --save-dev
In webpack context, this is not window like when adding common <script> tag,
this points to module.exports. This is handled by default by most libraries and when running in such mode,
no variables are registered in global context (window), they are just exported in CommonJS way.
This breaks things, as your current code expects to find jQuery, angular etc. in global context.
This bundle analyses JavaScript file for common patterns and tries to use correct loaders to fix these issues. This might not always work out-of-the-box. You can always use additional loader or modify the generated code - bundle only creates and replaces files in your repository, all other modifications to the code after that can be made manually.
Run replacement command:
app/console maba:webpack-migration:modify-twig-templates
Now your twig files are modified - you can safely remove both bundles (this one and MabaTwigTemplateModificationBundle)
from your kernel and vendors. You can just revert your changes in AppKernel.php, composer.json and composer.lock,
asserting that you've installed MabaWebpackBundle separately.
Running tests
composer install vendor/bin/phpunit
maba/webpack-migration-bundle 适用场景与选型建议
maba/webpack-migration-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 222 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「Symfony2」 「assets」 「assetic」 「amd」 「commonjs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maba/webpack-migration-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maba/webpack-migration-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maba/webpack-migration-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Caching and compression for Twig assets (JavaScript and CSS).
The bundle for easy using json-rpc api on your project
Bundle Symfony DaplosBundle
Tool for loading or deploying CSS and JS files into web pages
Symfony2 Barcode Generator Bundle with Twig function extension
统计信息
- 总下载量: 222
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-08