Code Monkey home page Code Monkey logo

Comments (15)

ihortymoshenko avatar ihortymoshenko commented on August 17, 2024

I think this is not necessary. Is it creates any problems?

from hearsayrequirejsbundle.

sprain avatar sprain commented on August 17, 2024

Could it be I am struggling with the same issue?
http://stackoverflow.com/questions/15680066/hearsayrequirejsbundle-javascript-files-not-found

from hearsayrequirejsbundle.

ihortymoshenko avatar ihortymoshenko commented on August 17, 2024

@sprain, are you sure that the path is exists? The addExternalNamespaceMapping method will be executed only if the path is an external. Perhaps, you specified the wrong path. Symfony contains resources such as css, images and js under the Resources directory in the directories with related names. Check again please.

from hearsayrequirejsbundle.

sprain avatar sprain commented on August 17, 2024

@IgorTimoshenko I might be misunderstanding something. So it isn't possible to keep JS files outside of the public folder and only serve them with Assetic over dynamically generated routes?

from hearsayrequirejsbundle.

ihortymoshenko avatar ihortymoshenko commented on August 17, 2024

@sprain, I meant that you should check whether the specified path is real.

from hearsayrequirejsbundle.

craigmarvelley avatar craigmarvelley commented on August 17, 2024

Also ensure that you clear your Symfony cache after registering new paths, that's caught me out a few times.

from hearsayrequirejsbundle.

jeremymarc avatar jeremymarc commented on August 17, 2024

I'm getting the same problem.

When I'm not using "external: true", paths for internal location are not output with the require config file (so requirejs cannot find my modules).
We need it for modules which are not located in the base_directory.

I've found a workaround, using "external: true" and specifying the location like this: "/bundles/acme/js" cc @hardchor.

from hearsayrequirejsbundle.

craigmarvelley avatar craigmarvelley commented on August 17, 2024

@hardchor The paths configuration node is for defining additional paths to the base_directory, which is the default. So the frontend path is redundant - your scripts should be available from the base directory.

Assuming you have this dir structure:

<bundle dir>
|_  Resources
     |_   scripts
          |_   main.js

and you're trying to load the main script like this:

{{ require_js_initialize({ 'main' : 'frontend/main' }) }}

Try removing that frontend path from the config, and instead load your main script like this:

{{ require_js_initialize({ 'main' : 'main' }) }}

AFAIK the base_url configuration is not necessary.

from hearsayrequirejsbundle.

hardchor avatar hardchor commented on August 17, 2024

Hi,

Having finally got the time to get back to this, I've got a bit of a better understanding of require and the bundle.

Many libraries like jquery plugins, moment.js etc. require named modules (i.e. jQuery defined as "jquery" and moment.js as "moment"). In vanilla require.js I'd define path aliases like so:

{
    baseUrl: "/bundles/acmedemo/js",
    paths: {
        controller: "src/controller",
        jquery: "vendor/jquery"
    }
}

The paths config for the bundle is not the same as for requirejs in that it tries to prefix any path key with the base URL (that's in NamespaceMapping.php#L83).
So, with the above config the bundle spits out paths like /bundles/acmedemo/js/jquery (which doesn't exist).

Am I doing something fundamentally wrong (it's working in require.js, so perhaps I'm not) or is there a reason why NamespaceMapping prepends the base URL to path configs rather than just passing them through to require.js?

from hearsayrequirejsbundle.

ihortymoshenko avatar ihortymoshenko commented on August 17, 2024

@hardchor, yes, you're right. The paths configuration is not the same.

You can specify in the paths configuration option:

  • a namespace as a prefix to prefix some module directory;
  • a concrete file without the .js file extension.

The main goal of this bundle is to expose directories where you store JavaScript files in order to provide the ability to the RequireJS load this files as modules.

That's current implementation. If you have proposals, feel free to contribute.

from hearsayrequirejsbundle.

hardchor avatar hardchor commented on August 17, 2024

I'm struggling to see a scenario where this would actually work as intended. Let's say I've got a AcmeDemoBundle and an AcmeOtherBundle. Now assuming the following config.yml:

hearsay_require_js:
    base_directory: "@AcmeDemoBundle/Resources/public/js"
    base_url:       "/bundles/acmedemo/js"
    require_js_src: "/bundles/acmedemo/js/vendor/require.js"
    paths:
        # make jQuery available as "jquery"
        jquery:     "@AcmeDemoBundle/Reosurces/public/js/vendor/jquery-2.0.1"
        # make "OtherBundle" resources available via "other" prefix
        other:       "@AcmeOtherBundle/Resources/public/js"

This would output the following require.js config:

var require = {
    baseUrl: "/bundles/acmedemo/js",
    paths: {
        "jquery" "/bundles/acmedemo/js/jquery" // <- this is where it goes wrong
        "other": "/bundles/acmedemo/js/other"  // not what I had in mind either
}

I think what I'll have to do to get around the named modules problem at least is to set my base_url as /bundles/acmedemo/js/vendor, rename jquery-2.0.1.js to jquery.js and then perhaps specify any other paths as externals.

from hearsayrequirejsbundle.

ihortymoshenko avatar ihortymoshenko commented on August 17, 2024

@hardchor, I see. What do you expect to get? Please correct me if I'm wrong.

{
    baseUrl: '/bundles/acmedemo/js',
    paths: {
        'jquery': '/bundles/acmedemo/js/jquery-2.0.1',
        'other': '/bundles/acmeother/js'
    }
}

Thanks!

from hearsayrequirejsbundle.

hardchor avatar hardchor commented on August 17, 2024

Yeah, that's it. I somehow worked around it in my implementation. I'll have a look tomorrow.

from hearsayrequirejsbundle.

adrian-ludwig avatar adrian-ludwig commented on August 17, 2024

Any progress on this ?
@hardchor can you share how you got it to work ?

from hearsayrequirejsbundle.

ihortymoshenko avatar ihortymoshenko commented on August 17, 2024

@hardchor, I've fixed this issue. As for the baseUrl option and prefixing each module path, you can specify this option to empty string and all should work properly. Perhaps, should remove the js default value for this option to prevent related issues. Let me know if it doesn't work for you.

from hearsayrequirejsbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.