0

I'm just starting with typescript and I'm trying to set up a multi-page amd app.

Keeping inline with the setup provided by the requirejs team I have a common.ts file that has all my requirejs configs, ex:

// common.ts
require.config({
    paths: {
        'backbone': 'lib/backbone'
        , 'jquery': 'lib/jquery'
        , 'underscore': 'lib/underscore'
    }
});

I then load requirejs with the following script tag:

<script data-main="http://blah/page1.js" src="http://blah/require.js"></script>

As instructed in the requirejs recommendations for a multipage app, I then load common.ts from within blah/page1.js and that's where I start having trouble.

What's the right way to import the commont.ts file?

I have not had any luck with import requireConfig = require('common'); since I'm not exporting anything from common.ts.

However, when I try to export anything, even a dummy value from common.ts it ends up wrapping the require.config() call in a module definition function which breaks stuff with requirejs.

I took a longshot by trying to load it using /// <reference path="common.ts"/> but of course that failed

I've also tried removing the import declaration and just calling require('common') but that fails to compile with Could not find symbol 'require'

Is there some way that I could load common.ts even though it does not export anything?

gxc
  • 4,946
  • 6
  • 37
  • 55

3 Answers3

1

You cannot import a file unless you export something from a file and you cannot export from a file and not have it wrap it up in a define when you compile for amd.

basarat
  • 261,912
  • 58
  • 460
  • 511
0

For anyone else coming up agains this problem, following up on @basarat's answer (basically, what I was trying to do is not possible) I've been able to resolve my problem by adding my requirejs config settings (e.g. the stuff that would have gone in common.ts) inline in my html template file according to the instructions provided in the requirejs docs.

So, my html looks like:

<script>
     var require = {
          paths: {...}
          , shims: {...}
     };
</script>

<script src="scripts/require.js"></script>

Not ideal, but it seems to be getting the job done for now.

Community
  • 1
  • 1
gxc
  • 4,946
  • 6
  • 37
  • 55
-1

Your shouldn't load the requires config file as an external module. You should use data-main and point it to this file. For an example see http://youtube.com/watch?v=KDrWLMUY0R0

this file should be you applications main entry point

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Sorry, I left that detail out and will update but yeah, I am using the data-main attribute. Only, per the requirejs multipage recommendation (linked to in my question), my data-main file is the one that loads the configs. – gxc Mar 26 '14 at 21:33