Typescript RequireJS import files

AlvinfromDiaspar

I have a basic question about RequireJS.

Currently i generate my Typescript files into a single outfile JS file. If i were to start using RequireJS, does this mean this single JS file would be eliminated?

My understanding is that RequireJS loads the JS file references at run-time. Is this correct?

Louis

If i were to start using RequireJS, does this mean this single JS file would be eliminated?

Not at all. You could still output everything to a single file. If you tell TypeScript to produce AMD modules and let it produce multiple files, you end up with a one-to-one relation between files and AMD modules: each file contains exactly one AMD module, and each AMD module is contained by exactly one file. If you tell TypeScript to produce a single file, you end up with a bundle of AMD modules: a single file contains multiple modules.

In all projects where I used AMD, I had TypeScript produce individual files and then processed the results with r.js (RequireJS' own optimizer) or Webpack. I suppose though there may be projects where letting TypeScript itself produce the bundle is a viable option. It really depends on the project.

My understanding is that RequireJS loads the JS file references at run-time. Is this correct?

This is true but it does not determine how you should organize your project at run time. Typically, a project will have a set of modules that won't run at all unless they are all loaded together, and these modules should be made into a bundle so as to load them in a single request instead of having to make a dozen requests to the server. Ultimately, you need to bundle modules in a way that makes sense for your project.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Typescript, Requirejs, import statement and aliases

Cannot import typescript files with the extension

How do I import other TypeScript files?

Typescript can't import files without extension

typescript - include a library import to all files

Typescript import with sending variable to imported files

How to import compiled files in typescript on fly (nodejs)

Import raw files from typescript with webpack using the `import` statement

Typescript RequireJs Shortcuts + Navigation

KnockoutJs components with RequireJs and TypeScript

Importing jqueryui with Typescript and RequireJS

Typescript Module + Webpack + RequireJS

Requirejs Angular and TypeScript

How to import strophe using requirejs?

import requirejs amd module with webpack

Automatic import refactoring when moving Typescript files in VSCode?

Import typescript files based on naming convention in React Native

Import third party js files to angular typescript project

How to include a typescript file for files in specific folder without import?

Typescript: how to import non .ts files as raw string

Typescript 1.8 modules: import all files from folder

Import JSON file in TypeScript declaration (*.d.ts files)

How to properly import variables and functions in angular typescript files?

Using RequireJS with TypeScript and Retaining Intellisense

Load several configuration files with RequireJS

Passing functions between RequireJS files

RequireJS + Bootstrap Datepicker + Locale Files

RequireJS: Optimized files and older browsers

RequireJS and TypeScript name.d.ts