MNGemignani / magento2_requirejs_disable

This is a simple module that helps you disable requirejs files for any module from magento2
6 stars 2 forks source link

RequireJS Disabling in config is not possible on store view level #1

Open amenk opened 5 years ago

amenk commented 5 years ago

Which was the whole point :-)

Can it be fixed?

Will look at it ...

amenk commented 5 years ago

We just have to set the config scope in backend to store_view level ...

When setting via magerun it's already working

MNGemignani commented 5 years ago

Its working now Alex?

amenk commented 5 years ago

I was just setting the config via Magerun... the system.xml still needs to be adapted -- did not yet have time for that, and wanted to check first if it is working generally (which it does)

MNGemignani commented 5 years ago

When I have time I will take a look on that also, thanks for the report

amenk commented 5 years ago

I have one big problem: The whole idea of having requireJS disabled on store view level does not work well on production mode ... the requireJS disabled on store view level does not work. It just stays enabled. When I switch to developer mode, it works.

Do you have any idea?

amenk commented 5 years ago

Somehow I cannot reproduce it anymore.

What I figured out is, that there is one requirejs-config per theme + language combination. While it does not make sense to exclude require js config per language, it also shows that my original approach is wrong -- to exclude requirejs per store view. Somehow we should make the config theme-dependent not store-view-dependent.

amenk commented 5 years ago

Okay, I still hat developer mode set in my Apache Vhost. I can reproduce the problem now

amenk commented 5 years ago

Possible Fix:

amenk commented 5 years ago

But we cannot just add config to the theme XML ---> so other option would be a configuration table in the backend where you can map themes to configurations.

amenk commented 5 years ago

Asked on SX https://magento.stackexchange.com/questions/262479/is-there-a-standard-way-to-make-add-a-config-on-theme-scope

MNGemignani commented 5 years ago

I merged your changes Alex, I will do some testing asp

MNGemignani commented 5 years ago

Alex I think I found the problem why it doesn't work on production mode, I just don't know how to solve it yet. At\Magento\RequireJs\Model\FileManager the getFiles function is used but a check is made to see the current mode:

private function ensureSourceFile($relPath)
    {
        $dir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
        if ($this->appState->getMode() == AppState::MODE_DEVELOPER || !$dir->isExist($relPath)) {
            $dir->writeFile($relPath, $this->config->getConfig());
        }
    }

If I remove this check the requirejs breaks on frontend and backend, any ideas?

amenk commented 5 years ago

For me it was working in production mode after my PR... The important part is, that reauireJS modules can be only disabled on per-theme basis, because the rewuireJs config is statically generated once per theme, not per store view

Did you test my PR in production mode and still encounter problems?

MNGemignani commented 5 years ago

I tested in production mode and magento2.3, I will do a new installation and check..

amenk commented 5 years ago

I am still not super with my approach -- would be better if requirejs could be disabled on a store view level. Still looking for a best practice.

MNGemignani commented 5 years ago

I tested your changes with Magneto2.2 and 2.3 and seems to work fine