Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Version of PR #62] Correct order of files when concatenating custom Javascript files to custom.js in case custom Html templates are used. #85

Closed
wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 31, 2018

Hi,

this is a polished version of the pull request #62. The problem it addresses remains (see description below).


Preliminary Remarks:

Workflow of custom template creation

When custome Html templates are defined (either in external npm modules or as part of a template package, the custom-html-templates tasks creates the file customTemplates.js in the js folder of the template package. It has the following contents

This file has the following contents:

app.run(function($templateCache) {
  $templateCache.put('[ID of custom template]','[HTML of custom template]');
  ...
});

Subsequently, this file is concatenated by the custom-js task with all other Javascript files present in the js directory of the template package to a single Javascript file called custom.js which is then saved also in the already mentioned js.

The problem

(1) The customTemplates.js contains Javscript code that calls the run method on an custom angular module referenced by the variable app.

(2) In order for the Javascript code in the final concatenated custom.js file to work properly, the code contained in the customTemplates.js file needs to be placed after the code contained in the file that is responsible for instantiating the angular module and assigning it to the variable app. Otherwise an error will be thrown.

(3) Right now the code that instantiates the angular module and assigns it to the variable app is defined in a file called main.js (At least that is my assumption). Given the fact that the custom-js tasks concatenates files in alphabetical order, the Javascript code in the customTemplates.js file will be placed before the Javascript code in the main.js file, causing an error to be throwing that signals that the variable app is not defined.

The solutions

(1) Put the code that instantiates the custom angular module and binds it to the variable app in a file that in alphabetical order comes before the file customTemplates.js. It is quite easy to do, however not very intiutive, since the aforementioned behaviour is nowhere clearly documented.

(2) Provided, that the code which instantiates the custom angular module and binds it to the variable app is put in a file called main.js, change the order of the files before they are concatenated.

This pull request offers an implementation of solution 2 using gulp-order.

Best regards, Matthias

@ghost ghost changed the title Fix js build order [New Version of PR #62] Correct order of files when concatenating custom Javascript files to custom.js in case custom Html templates are used. Aug 31, 2018
Copy link
Contributor

@gilax gilax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand the order you asked for. Why does the custom.module.js file is after the main.js?

gulp/tasks/buildCustomJs.js Show resolved Hide resolved
@gilax
Copy link
Contributor

gilax commented Dec 10, 2018

Hi Meinbrodt,

The concept of the custom.module.js file is like the naming convention provided by Angular, which means that this file contains the Angular's module and all the dependencies that the module using by inject them to the module. What we meant by binds it all together in this order is that the module file will define the app variable as the module and the main.js file will contain the main component or any other code that needed in the customization package.
From what I saw in this PR this is answering the main problem you are trying to answer, but if I'm wrong you are more than welcome to correct me.

Kindly yours,
Gilax

@gilax gilax closed this Dec 11, 2018
@ghost
Copy link
Author

ghost commented Dec 11, 2018

Hi Gilax,

thanks for your response.

The concept of the custom.module.js file is like the naming convention provided by Angular, which means that this file contains the Angular's module and all the dependencies that the module using by inject them to the module.

I think I get it now. Instead of using the main.js file for defining my custom view package/module logic I'll use the custom.module.js file now which should solves this issue. I let you know once I tried it.

Just one quick quesiton. What is the role of the main.js file exactly?

Cheers, Matthias

@gilax
Copy link
Contributor

gilax commented Dec 11, 2018

Hi Matthias,

You can think of the main.js as the main component/global functions that used in the package. You can use the main.js file as your main file, and just move the app variable to the custom.module.js file.

Thanks,
Gilax

@ghost ghost deleted the fix-js-build-order branch December 14, 2018 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant