Reputation: 2266
Let's say I have the following TypeScript file:
import module1 = require( 'module1' );
import module2 = require( 'module2' );
...some code...
This would generate the following JavaScript on compilation:
define( [ 'require', 'exports', 'module1', 'module2' ], function ( require, exports, module1, module2 ) {
...
}
However, what if I want to include a file that's NOT a TypeScript module? I want it to be loaded by RequireJS, as it has dependencies that are also loaded by RequireJS. If I try to add e.g. this:
import someJsFile = require ( 'someJsFile' );
I just get a "Module cannot be aliased to a non-module type" error on compilation. If I skip the import
part and just do require( 'someJsFile' )
, it compiles, but the JavaScript it generates is a non-functional nested define instead:
define( [ 'require', 'exports', 'module1', 'module2' ], function ( require, exports, module1, module2 ) {
define( [ 'someJsFile' ], function ( someJsFile ) {
...
}
}
Is there any way of including JavaScript files in the outer, "correct" RequireJS define without having to convert the JS files to TS modules myself? Or do I have to manually create a RequireJS define and drop the import x = require( 'x' )
statements altogether?
Upvotes: 1
Views: 480
Reputation: 276181
Use amd-dependency
. In your case :
/// <amd-dependency path="someJsFile" />
declare var someVarFromJsFile: any;
Upvotes: 2