Comments (15)
I think this is not necessary. Is it creates any problems?
from hearsayrequirejsbundle.
Could it be I am struggling with the same issue?
http://stackoverflow.com/questions/15680066/hearsayrequirejsbundle-javascript-files-not-found
from hearsayrequirejsbundle.
@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.
@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.
@sprain, I meant that you should check whether the specified path is real.
from hearsayrequirejsbundle.
Also ensure that you clear your Symfony cache after registering new paths, that's caught me out a few times.
from hearsayrequirejsbundle.
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.
@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.
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.
@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.
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.
@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.
Yeah, that's it. I somehow worked around it in my implementation. I'll have a look tomorrow.
from hearsayrequirejsbundle.
Any progress on this ?
@hardchor can you share how you got it to work ?
from hearsayrequirejsbundle.
@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)
- Packages/paths with .js in the name cannot be used
- 2.0 does not support build_profile option in bundle configuration HOT 23
- Assetic filter with production flag causes 404 errors in dev environment HOT 13
- assetic:dump --watch keeps generating files HOT 1
- Setting hide_unoptimized_assets to false causes an InvalidConfigurationException HOT 5
- extra template neccessary for require.js HOT 1
- require_js Twig global no longer created
- Almond integration
- How can I use modules for r.js? HOT 2
- Service ("templating.helper.assets") on cache:clear
- directories specified in the array "paths" in yml configuration file are not processed correctly
- Twig Exception about Template name...
- Undefined method HOT 7
- Incorrect <script> output in production
- Create a recent tag HOT 1
- Fix src() method in RequireJSHelper.php HOT 1
- Use this bundle with php templating engine (not twig)
- enable JS File loading from public folders to increase performance in development HOT 1
- Multiple bundles? HOT 1
- The child node "base_directory" at path "hearsay_require_js" must be configured. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hearsayrequirejsbundle.