Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using a require js config #64

Open
willm opened this issue Apr 23, 2015 · 7 comments
Open

using a require js config #64

willm opened this issue Apr 23, 2015 · 7 comments

Comments

@willm
Copy link

willm commented Apr 23, 2015

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
Copy link
Owner

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:

  • The requirejs.config.json file thing works only for template: 'UMD'(http://urequire.org/umd-template) and of course the file is read only when executing on nodejs. So you're right on having to call require.config() on a web environment (perhaps on main.js, perhaps somewhere else).
  • it relies on RequireJs to do it (even on nodejs, and its a bit of a hack - see
    rjsConfig["requirejs._.config.baseUrl"] = rjs.s?.contexts?._?.config.baseUrl
    rjsConfig["requirejs._.config.paths"] = rjs.s?.contexts?._?.config.paths
    ), so I am not sure what implications this trickery might have!
  • Your right about bundle.copy, by default it copies nothing.
  • May I ask, why do you want to rename your dependency and not simply move it on the root of ./source or use a require(['wibble'], ... ?

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

@willm
Copy link
Author

willm commented Apr 28, 2015

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
Copy link
Owner

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
Copy link
Author

willm commented May 5, 2015

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants