requirejs / almond

A minimal AMD API implementation for use after optimized builds
Other
2.42k stars 169 forks source link

Return almond.js as string when required from node.js #102

Closed zanona closed 9 years ago

zanona commented 9 years ago

I am implementing a solution where It's possible to automatically inject almond as a replacement for requirejs through r.js's optimize rawText attribute by having the following call:

requirejs.optimize({
  baseUrl: process.env.VENDOR_PATH,
  name: 'almond',
  include: ['main'],
  insertRequire: ['main'],
  rawText: {
    'almond': fs.readFileSync(require.resolve('almond')).toString(),
    'main': dataFromMain
  },
});

However as it's possible to see, there is a slight process to be done before retrieving contents for almond.js which in my module's dependency list. Considering this, I would like to suggest that when required through node.js, almond returned its string content instead? —Currently require('almond') results in {}.

jrburke commented 9 years ago

almond is not designed to be a node module, and I think it is fairly non-standard for a node module to just return the text of itself. I would prefer to not do this.

You could set a requirejs paths config in that object passed to reuqirejs.optimize() for 'almond', and the value I think would just be require.resolve('almond'), and then the optimizer will do the text work for you.

zanona commented 9 years ago

Thanks, I will try that instead. I was just wondering that the reason for almond being available through npm could have something to do with a way to use it through nodejs for automation.