How to use Assetic for requireJs

I am trying to use require.js in a synfony2 project.

Here is the code in the main twig file:

<script data-main="{{ asset('bundles/web/js/main.js') }}" src="{{ asset('vendor/js/require.js') }}"> </script> 

The vendor/js/require.js file is loaded correctly, but for the bundles/web/js/main.js I get the message:

Unprepared error: load timeout for modules: mainApp.js? 201205021855 http://requirejs.org/docs/errors.html#timeout

I am using RequireJS 1.0.8. Any idea how to solve the problem? Thank you


If you look at the original page, it looks like this:

 <script data-main="/~myName/myProject/web/bundles/web/js/main.js?101205021855" src="/~myName/myProject/web/vendor/js/require.js?101205021855"> </script> 

So, the paths are rights, but in the javascript console I get the following message:

GET http://localhost/~myName/myProject/web/app_dev.php/main.js?201205021855 404 (not found)

+4
source share
3 answers

Adding to @ dgabriel's answer. You can do this using the cut filter,

 <script data-main="{{ asset('bundles/web/js/main.js') | slice(0, -3) }}" src="{{ asset('vendor/js/require.js') }}"> </script> 
+2
source
  • Remember to leave the .js file extension out of your assets. Must be data-main = "{{asset ('bundles / web / js / main')}}

  • Make sure your file path is correct.

  • Make sure there are no javascript errors in main.js

+1
source

It looks like 404 looks like the β€œmain thing” is required somewhere else in your application β€” it does not match the path in your main database. In this case, it is most likely a problem with the configuration of baseUrl or paths (both of which are different ways of telling RequireJS where your modules are located). In your example, your baseUrl should be "/ ~ myName / myProject / web / bundles / web / js".

You might want to use https://github.com/hearsayit/HearsayRequireJSBundle . It automatically processes this configuration data and automatically integrates with Assetic.

0
source

Source: https://habr.com/ru/post/1411625/


All Articles