Require.js does not load files or modules from base directory

0

I am implementing Require.js to modularize my application and load the js files asynchronously and leave the html of the script tag cleaner, I find the following problem and it requires js not to load the jquery file.

I have the following folder structure:

+ Carpeta de proyecto
  + App
    + Views <- Vistas HTML
    + Scripts <- Scripts para las vistas
    - Main.js <- Configuracion de require.js
  + Vendor <- Librerias de javascript
    + JQuery
      - jquery.min.js
    + Require
      - require.js
  + Index.html <- Pagina de inicio

in the main.js file I have the following:

( function ()
{
    'use strict';

    require.config(
        {

            paths:
            {
                'jquery': '../Vendor/JQuery/jquery.min' // <- la carpeta de encuentra un directorio arriba
            },

            shim:
            {
                'jquery':
                {
                    exports: '$'
                }
            }
        } );
} )();

up here all right but when I try to use jquery from the index

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Index</title>
</head>
<body>
    <div>
        <button id="demo">Click</button>
    </div>
    <script data-main="App/Main" src="Vendor/Require/require.js"></script>
    <script type="text/javascript">
        require( [ 'jquery' ],
            function ( $ )
            {
                $( "#demo" ).click( function ()
                {
                    alert( 'Click' );
                } );
            } );
    </script>
</body>
</html>

I get an error that the script is not found and apparently require.js is looking for the jquery in the App folder and I have the Vendor folder inside:

                                        directorio
                                            |
require.js:1961 GET http://localhost:10202/App/jquery.js net::ERR_ABORTED 404 
require.js:168 Uncaught Error: Script error for "jquery"

is totally ignoring the jquery path that I put in the app.js

    'jquery': '../Vendor/JQuery/jquery.min'

if in the app.js file I put the index code works correctly and jquery is loaded

    require.config(
        {

            paths:
            {
                'jquery': '../Vendor/JQuery/jquery.min'
            },

            shim:
            {
                'jquery':
                {
                    exports: '$'
                }
            }
        } );

    require( ['jquery'],
        function ( $ )
        {
            $( "#demo" ).click( function ()
            {
                alert( 'Click' );
            } );
        } );

but for me to work from the index I have to put the path of the file

require( ['../Vendor/JQuery/jquery'] function ($)

How do I solve this?

Why does require.js ignore the path?

Sorry for the inconvenience just start with this library.

    
asked by Deiby Olaya Orejuela 13.11.2018 в 17:09
source

0 answers