ponbike / require-js-optimizer
Ponbike RequireJS Optimizer
1.1.3
2020-02-03 09:13 UTC
README
此模块将在部署工作流程中实现WeareJH创建的config-gen模块(请参阅https://github.com/WeareJH/config-gen以获取详细信息),并且仅在运行生产模式时添加包。
步骤 1 - 下载二进制文件
从WeareJH config-gen存储库下载最新的config-gen
发布版,并将其存储在项目的bin目录中。此外
步骤 2 - 编辑配置文件
将require-js-optimizer-config.yaml.dist
重命名为require-js-optimizer-config.yaml
,将require-js-optimizer-bundle.yaml.dist
重命名为require-js-optimizer-config.yaml
。然后编辑require-js-optimizer-bundles.yaml
以满足您的需求。
步骤 3 - 收集数据
接下来运行config-gen命令
Step 4 - Store the collected data in your project
---
When all pages are recorded download the recorded data:
`build.json`
The build.json data is used to run the requirejs optimizer command, store the contents of [https://:12345/__bs/build.json]() to `require-js-optimizer-build.json` in your project root.
`loaders.js`
The loader.js data is used to load the bundle configuration for your theme, this file needs to be placed in the active theme and will only be included when the environment is running in production mode. Store the contents of [https://:12345/__bs/loaders.js]() to your theme in the file `Ponbike_RequireJSOptimizer/web/js/requirejs-loader.js`
Step 5 - Install r.js
---
Run `npm install -g requirejs`. For further instructions see https://github.com/requirejs/r.js/blob/master/README.md.
Step 6 - Build the optimized bundles
---
Make sure to switch to production mode (`bin/magento deploy:mode:set production`), otherwise the bundle loader will not be included.
To optimize the RequireJS files, you first need to deploy the static content (`bin/magento setup:static-content:deploy`), when completed run the optimizer script:
```bin/require-js-optimizer.sh```
Step 7 - Optional, only if you deploy to Magento Commerce Cloud / platform.sh
---
In order to run the optimizer during the deploy (in the build-phase) update your `.magento.app.yaml` (or `.platform.app.yaml`) file:
```
hooks:
# We run build hooks before your application has been packaged.
build: |
set -e
php ./vendor/bin/ece-tools build:generate
bin/require-js-optimizer.sh
php ./vendor/bin/ece-tools build:transfer
# We run deploy hook after your application has been deployed and started.
deploy: |
php ./vendor/bin/ece-tools deploy
# We run post deploy hook to clean and warm the cache. Available with ECE-Tools 2002.0.10.
post_deploy: |
php ./vendor/bin/ece-tools post-deploy
```
Also you need to disable the GZIP-ing of the static content during the ece-tools build:generate command, do disable the GZIP update the `.magento.env.yaml` file:
```
stage:
build:
SCD_COMPRESSION_LEVEL: 0
```