Skip to content

Instantly share code, notes, and snippets.

@shakyShane
Created October 10, 2018 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakyShane/41430cb9f84d6cbf6cea92164da7d915 to your computer and use it in GitHub Desktop.
Save shakyShane/41430cb9f84d6cbf6cea92164da7d915 to your computer and use it in GitHub Desktop.

config-gen

Generate RequireJS Optimizer configuration for Magento 2 website based on real-world usage.

Step 1 - Download the binary

config-gen is packaged as a single binary (currently only osx) to enable easy usage, just check the releases page and download the latest.

This will provide you with a new url, something like http://127.0.0.1.

Step 3 - create a configuration file, call it config-gen.yml

presets:
  - name: m2
    options:
      bundle_config: file:test/fixtures/bundle-config.yml

Step 4 - create the bundle-config.yml file as noted above.

bundles:
  - name: bundles/main
    urls:
      - "/"
      - "/index.php/women/tops-women/jackets-women.html"
    children:
      - name: bundles/product
        urls:
          - /index.php/juno-jacket.html
        children: []

Step 4 - Now run the program against a Magento 2 instance

./config-gen http://example.com --config config-gen.yml

Step 5 - access the APIs

At any point, you can access the following endpoints to retrieve the generated json/js

Path Purpose
/__bs/build.json Generates the configuration needed for the Optimzer
/__bs/loaders.js Generates the JavaScript needed to load additional bundles
/__bs/seed.json Generates a dump of the current state so that you can pick up where you left off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment