magesuite / magepack

Next generation Magento 2 advanced JavaScript bundler.
Open Software License 3.0
434 stars 91 forks source link

Feature Request - Manual entries in local config file to be merged with crawled results #17

Closed gwharton closed 1 month ago

gwharton commented 4 years ago

Provide the option for a local config file, that could be read, which is in the same format as the magepack.config.js file, and merge these entries with the ones produced from the crawl. Thus allowing users to manually add things to the bundles that don't get picked up by the automatic crawl (perhaps they only appear on one page somewhere that wasn't crawled)

gwharton commented 4 years ago

An example of a use case for this. I set magepack to crawl urls on my staging environment during deployment. However the staging environment does not have Google Tag Manager enabled, to avoid it firing off to google during deployment. Therefore I could add this entry manually as I know it will be skipped. Another use case, my staging environment does not contain any sales infomation, so my homepage that usually includes a list of best selling products along with some javascript slider functions also does not appear. This could also be added manually.

krzksz commented 4 years ago

Would it be enough that the newly generated config would merge into (instead of overwriting) an existing one if it finds it?

gwharton commented 4 years ago

It would be ok for me as my initial magepack.config.js file with manual entries would be grabbed from source control, then added to by the magepack program and finally used to deploy the site. For every deploy a fresh copy of my local file would be grabbed from source control. Not everybody operates like that though. I can see that approach being problematic for the way that some users operate. I can hear some screaming "Why does it overwrite my file!!!! Now ive gotta remove all these entries if I want it to recrawl from fresh". Successive reruns of magepack would end up crawling the site and then deferring mostly to what is in the existing config file. Entries that are no longer valid would only be removed by manual intervention. A better approach would be to merge contents from magepack.config.local.js into the final magepack.config.js leaving the users local file unchanged.

gaiterjones commented 4 years ago

@gwharton @krzksz do you have any tips for troubleshooting console errors seen after bundling. I have a couple an errors affecting a product slider, although the slider js appears to be included in the bundled file.

gwharton commented 4 years ago

Have you looked at PR 27690 aswell as the required 25587. 27690 was needed to resolve js errors for me.

gwharton commented 4 years ago

@krzksz I was thinking it would probably be easier to do the merging at the "magepack bundle" stage, as it just needs to read magepack.config.js and magepack.config.local.js (if exists) and merge the two arrays in memory and get rid of duplicates.

Paulsky commented 3 years ago

@gwharton May I ask you what your workaround on this is? Because we have somewhat the same scenario (different JS code in different environments).

Maybe ignore the magepack.config.js in GIT for now? And then on each deployment:

Not sure if this is the right way to go?

gwharton commented 3 years ago

Hi Paul,

Our deployment goes something like this.

On Development Node

On production Node

You can see we create the magepack.config.js file from scratch every time we deploy by running magepack against our staging site which we have preprepared with all of the necessary cms pages and products to make it browseable and contain products. You only need to ensure you have enough content for the three magepack urls, plus ability to add product to cart.

Once that is done we manually use grep and awk (it would be nice if there was an easier way to add/remove entries from the config without having to manually awk and grep it) to modify the set to remove items that result in errors after bundling, or add things that we know will have been missed.

Then the staging site files are tar'd up and transfered to production nodes, followed by db upgrade on production node. The staging site is then culled.

We also run some MFTF tests against our staging site to make sure some key customisations are not broken.

The whole thing is wrapped up in a single deploy.sh script.

Probably more detail than you asked for here, but may spark some ideas.

Paulsky commented 3 years ago

@gaiterjones Thank you so much for your detailed answer! I really appreciate it! Indeed a little more detail what I asked for but this is helping me a lot, thank you once again!