Giter VIP home page Giter VIP logo

magento-rjs-config's Introduction

magento-rjs-config

NOTE This readme is deprecated. See https://devdocs.magento.com/guides/v2.3/performance-best-practices/advanced-js-bundling.html

NOTE Configuration generation tool that automates build.js creation was created by Shane Osbourne: https://github.com/WeareJH/config-gen

This r.js build file is built for Magento 2.2.0-rc30 CE Luma theme.

NOTE: Manual modification of the build.js file for your project IS NOT REQUIRED. A major benefit will be achieved by any Magento/blank or Magento/luma-based installation with this build configuration without the need for any modifications. Tweaking the build.js file is optional if you want to achieve 100% improvements.

The Magento 2 built-in bundler relies only on PHP, which is not very efficient and could lead to potential issues. The build file build.js from this repository can be used to execute bundling and minification on deployed static content with the r.js tool shipped with the NPM version of RequireJS. It will optimize the main pages of Magento 2.

The process described here should be applied only during deployment to production.

Usage

  • Install r.js
  • Download build.js from this repo
  • Edit build.js to remove/add files from your custom theme to bundles (optional)
  • Apply the jquery.cookie issue patch
  • Run magento setup:static-content:deploy to deploy Magento 2 static content to {magentoDir}/pub/static/ folder
  • For every theme locale that you use:
    • Move {magentoDir}/pub/static/{area}/{vendor}/{theme}/{locale} folder to {magentoDIr}pub/static/{area}/{vendor}/{theme}/{locale}_source
    • Run r.js -o build.js baseUrl={magentoDir}/pub/static/{area}/{vendor}/{theme}/{locale}_source dir={magentoDir}/pub/static/{area}/{vendor}/{theme}/{locale}

Output

  • Bundles all files common for all Magento 2 Luma storefront pages into requirejs/require.js file
  • Generates 5 page-specific bundle files:
    • bundles/default.js - should be added to default layout handle
    • bundles/cart.js - should be added to checkout_cart_index layout handle
    • bundles/checkout.js - should be added to checkout_index_index layout handle
    • bundles/catalog.js - should be added to catalog_category_view and catalog_product_view layout handles
    • bundles/product.js - should be added to catalog_product_view layout handle

Adding bundles to pages

To add a bundle file to the corresponding page, add following instruction to the page layout update file in your module:

  <head>
    <script src="bundles/{bundleFile}.js" />
  </head>

Example for cart pages, create a file My/Module/view/frontend/layout/checkout_cart_index.xml with the following contents:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="bundles/cart.js" />
    </head>
</page>

Fixing missconfiguration of jquery.cookie

JQuery.cookie module should be added to 'deps'. To add, create a 'requiejs-config.js' file in your module:

//My/Module/view/frontend/requirejs-config.js
var config = {
    'deps': ['jquery/jquery.cookie']
};

magento-rjs-config's People

Contributors

antonkril avatar erikhansen avatar jissereitsma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magento-rjs-config's Issues

Uncaught TypeError: Cannot read property

I am getting following error . build is working file .site is working. but getting these 2 errors.
Please let me know if this can be fixed.

require.js:194 Uncaught TypeError: Cannot read property 'getItem' of undefined

TypeError: Cannot read property 'setConf' of undefined

Desktop screenshot

Error JS on console, jquery.cookie seems to be not loaded properly

Hi @antonkril
I really appreciate this idea. Running Magento with bundle js should make the performance better.

Anyway, I am trying to implement this r.js bundling on Luma. The bundles files are generated successfully. They are loaded on the related page successfully as well. Unfortunately, it is not really working.
There is an error in the console. Here is the error:
error on console
error location

I am guessing seems the jquery.cookie is not loaded properly.
Is it related to your concern about the cookies issue on this part? https://github.com/antonkril/magento-rjs-config/#fixing-missconfiguration-of-jquerycookie
I did try this step, I was creating a new requirejs-config.js under Magento_Theme module, and put the jquery/jquery.cookie as deps there. But the error persist, it bring another error on console instead.
another error
Both error actually are similar. it says that cookieStorage is not defined.

Do you have any idea about what is going on here?
Thank you very much in advance! Really appreciate your help.

Support javaScript mixins

Hi Anton,

I know this gist is deprecated and I'm trying to use the guide for Magento 2.3 (https://devdocs.magento.com/guides/v2.3/performance-best-practices/advanced-js-bundling.html) to bundle the javascript, but I run into the problem that mixins aren't loaded for components that I extended.

I've tried including the 'mixins!Magento_Ui/js/lib/knockout/bindings/bootstrap' assets in the modules right after 'Magento_Ui/js/lib/knockout/bindings/bootstrap', for example. But this seems to cause to not load and stop JavaScript. I can't just leave out the components that have mixins assigned to them, because then I would need to strip out any component that get's extends by any (core, own, third party) module. Do you think it can be achieved at all? And perhaps how?

Perhaps I should direct Adrew Levine about this, though, but this gist is my only lead so far.

Bundled JS files still downloaded separately

Hi,

Thanks for your work on this configuration and instructions on using the RequireJS optimizer.

I have an issue with files that are included in the bundle still being downloaded as before. It seems that the only change is that the file will get downloaded twice (once as part of the bundle, and once as part of the way RequireJS normally works). Is there some further configuration required to tell RequireJS that the files have already been downloaded?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.