Should compiled JavaScript files be committed to Git repo? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
New to TypeScript here and just wondering what the community views as best practice.
When I compile for production, I use the webpack loader. However, when I run my tests, I need to run tsc && ava. This generates a .js equivalent file in the same location as their .ts counterparts. Should these by committed to the repo alongside the .ts files? My first assumption is no because they should be re-compiled each time before a process e.g. starting your server or executing tests is run. However, I'd just like to get the community's opinion on this.

Your assumption is absolutely correct - build artefacts and outputs shouldn't be added to your repository. The main reason for this is that it's easy to end up in a situation where the source .ts file has changed but the compiled .js file differs because it's not been committed at the same time.
You also add complexity to your pull-requests/merge reviews, as there will be a large amount of generated code that isn't really part of the review but is in the changeset.
Finally, merging changes becomes a bit of a pain, because you need to recompile the .js files for every merge you do.
If you only use .ts files in your source directory, you can add /**/*.js to your .gitignore to prevent files from being added accidentally.

Related

What is the Difference between amd.js file & main.js file in a dist folder of Javascript node project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Question is related to javascript project which uses node and web pack.
I see in my current project there is node_module -> lib folder , there is xyz.js file in lib folder.
And in dist folder of node_module there is xyz.amd.js & xyz.main.js & respective js.map
I would like to know what is difference between amd & main.js files
And how the Current project which contains this node_module folder uses these files.
If you can point me to any site/tutorial explaining these. it would be helpfull
node.js will load those modules from local the node_modules/ directorywhen it encounters statements such as:
var xyz = require("xyz");
Or
import xyz from 'xyz';
"amd" refers to the Asynchronous Module Definition API, which loads modules in a lazy fashion (i.e. as needed). I suspect your xyz.amd.js module is for the AMD loader.
https://github.com/amdjs/amdjs-api/wiki/AMD

When should i build 'dist' folder and when i should not? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I know dist folder is used for production, distribution and what it should contain.
What i want to know is, when is the best time to use it? in what kind of work environment/project requirement i should use dist folder? like Heroku, what are the other platforms where i can deploy an app without dist and the platforms where i can't deploy without it (if there is any)?
I'm new to this, if someone can clearify the process would be very much helpful.
The dist folder is for production website it's not necessary to have it. It will contain for example your image, css, script, vendor folder ready for production (minified and concatenated).
You can check on google for this. Type "how to deploy a production React app to Heroku" for example.

What is the workflow when including scripts in web pages with npm? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
There are many JS libraries and frameworks (e.g. jquery) that suggest doing this:
npm install foo
This gives you a node_modules directory in which there would be a foo directory. For most JS libraries that are meant for use in web pages, there will be a dist directory inside consisting of the required JS files that can be used.
I can now include JS with something like <script src="/node_modules/foo/dist/foo.js">, but I haven't found a single website doing that. Of course, this folder could be symlinked to something like js and then that could be used as js/foo/dist/foo.js, although I'm not sure if this is a good idea or whether it is even done in real life.
To me, copying scripts from online sources and putting them in my project repository seems like a better idea, although the advantages of automatic package management are lost in that case.
I do understand the workflow of npm when developing node.js-based server side applications, however, I'm having trouble understanding where the case involves scripts to be included in web pages. What exactly is the workflow in such cases?
Well, do use NPM installed scripts in a web you have to use some bundler/builder which adds additional layer package management in your application. This would allow using modules like in server side. After bundling your modules into single or multiple chunks include these in your web like any other JavaScript files.
There are multiple tools for such job:
http://browserify.org/
https://webpack.github.io/
http://rollupjs.org/
Loading JavaScript in the browser is usually done through a module system, for which there are several competing standards (AMD, CommonJS) and implementations. One such implementation is Browserify, which assembles (at build time) the scripts you actually require into a single bundle.js file, which you can then easily include in HTML. (Other module systems work differently, for instance by loading each file separately when it is first needed).

Best Practice - ASP.NET Combine all JavaScript output [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am curious as to what the best practice is to combine all JavaScript into one file. I am using Visual Studio ASP.NET MVC 5 and TypeScript. I also have jQuery and a bunch of plugins, as well as my own page specific JavaScript fies.
Visual Studio has an option under Build Options -> TypeScript Build to "Combine JavaScript output into file".
Does this combine only the JavaScript generated from the my TypeScript files, or will it also combine jQuery and the various plugins?
Is there any possibility for collisions (multiple .ts files having the same variable name), or does TypeScript natively avoid that?
The typescript build option (--out in tsc) will only concatenate the typescript within the project. You may run into issues with file ordering if you use this. Using CommonJS with browserify solves this issue, though the TypeScript project itself uses the --out option for building the typescript compiler. Nevertheless this will not concatenate your vendor library files like jQuery.
The best option is to use gulp or grunt as part of your build process to concatenate and uglify your compiled Typescript and Javascript.
You should not be using global variables and thus will not have variable collisions. Instead your code should use modules. This can be the traditional javascript module pattern which is equivalent to Typescript modules, or the AMD modules like Require.js or CommonJS modules which actually are better suited for concatenated code.

Recommended Intern directory structure for multiple package testing [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have gone thru the intern-tutorial which is a very simple unit test case. However, it's not clear to me if the directory structure can be different and how flexible intern's configuration can be to accommodate it.
I'd like to find a tutorial that showed the v1.1 intern locations expected... which locations are mandatory and which can be modified and how that impacts the config file (intern.js) settings. What is the directory structure intern expects for a project and what is changeable, such as when you have multiple packages even.
In particular I'd like to see the relative location relationships of the:
web root
intern dir
intern.js config file
unit-test files
dojo/dijig/dojox/etc package location
modules in a package
Please show how placement relates to the configuration settings if possible.
As of Intern 1.1, the only thing that is mandatory is that Intern be installed as an npm dependency of the root project being tested. There are no relationships to any of the things you asked about, except that everything needs to be within the project’s root directory.

Categories