anodynos / uRequire

The Ultimate JavaScript Module Builder & Automagical Task Runner. Convert AMD & CommonJS/NodeJS modules to UMD, AMD, CommonJS or bundle them as `combined.js` (rjs & almond, AMDclean soon) & automagically run/test/watch them on nodejs, Web/AMD or Web/Script. Declarative & DRY config with inheritance. Manipulate & inject dependencies, module code, banners, version etc while building with a single line. Support two kinds of plugins, ResourceConverter (i.e file level) and AfterBuilder (i.e the whole bundle). Transparent support for Coffeescript, IcedCoffeescript, Coco, LiveScript – they’re just JavaScript :-)
http://anodynos.github.io/uRequire
MIT License
265 stars 20 forks source link

using a require js config #64

Open willm opened 9 years ago

willm commented 9 years ago

Hi,

I'm trying to use a requirejs config (speciically the paths option). I've followed the guide and added a requirejs.config.json file at the root of my bundle, however, the built code does not seem to be using the config.

My project structure looks like this: scripts --nested ----path ------wibble.js --main.js --require.js --requirejs.config.json

my urequire config looks like:

'use strict';
var config = {
    bundle: {
        path: './scripts',
        name: 'urequire testing'
    },
    build: {
        dstPath: './scripts/build',
        template: 'AMD',
        verbose: true,
        debugLevel: 30,
        globalWindow: true
    }
};
module.exports = config;

my main.js looks like:

require(['wibble'], function (){});

my requirejs.config.json looks like:

{
    "paths": {
        "wibble": "nested/path/wibble"
    }
}

Do I need to call require.config() in main.js? If so what do I pass to it? It also doesn't seem like requirejs.config.json is being copied to the build folder. I tried adding it explicitly to the urequireconfig bundle.copy array which did copy it, but it is still not being used. Thanks for any help!

anodynos commented 9 years ago

If I understand correctly, you want to have something as an alias or short cut of "wibble" to "nested/path/wibble", right ? If not, what is your pain here ?

In this case, this should work, but keep in mind:

PS: I would NOT use dstPath: './scripts/build' under path: './scripts' - better keep 'em separated into ./source & ./build or something.

willm commented 9 years ago

Thanks for your response, I tried switching the template to UMD, and moved the build directory up a level. However the requirejs.config.json still doesn't appear to be processed. You say I'll need to call require.config(x) however, what do I pass into this method as x?

The reason I'm trying to do this is I have some "legacy" cleint side codewritten in AMD. I would like to use urequire to deprecate the use of amd gradually, so that I can use commonjs modules throughout the entire application (the server is written in nodejs) without having to rewrite all the client side code in one go. The existing client side code has several aliases mentioned in the requirejs config. I'd like to avoid having to change too much of the structure of the code which is why I'm looking to use the existing aliases.

Is there an example using the requirejs.config.json somewhere?

anodynos commented 9 years ago

However the requirejs.config.json still doesn't appear to be processed.

What do you mean not processed ? Is it copied to the build.dstPath ? It would help if you can give access to your repo OR if you can create a minimalistic repo with sample files that follow your problem, so we can test your scenario.

You say I'll need to call require.config(x) however, what do I pass into this method as x?

The require.config(x) is for the browser enironement only - you should pass the same config as in requirejs.config.json` (which is used only on the node env.).

Hope this helps

willm commented 9 years ago

Sure, I've created a repo which hopefully explains the issue.

git clone https://github.com/willm/urequire-issue.git
npm install
urequire config urequire-config.js

If you then open test.html in your browser and look at the javascript console, you will see a script error for wibble. The requirejs.config.json will not appear anywhere in the build directory.

Again thank you for your help with this.

anodynos commented 9 years ago

Sorry my friend, I have been hectic with work - I will look into this over the next few days and I will get you an answer - hope this is ok !

anodynos commented 9 years ago

In your urequire-config.js you were limiting bundle.filez to *.js only, and also bundle.copy by default doesn't copy anything. So requirejs.config.json wasn't being copied.

Changing these (running in node), it caused another problem (crashing, internal to uRequire) which I will have to look closer...

Hopefully this week!

Regards and sorry for delayed response... new country, new job, new life you see!

Regards

anodynos commented 9 years ago

Also in your HTML, I guess you should be calling require.config({}) passing the same config as in requirejs.config.json for the paths aliases.