简体   繁体   中英

why doesn't this simple require.js setup work?

I'm trying to learn how to use require.js to load my scripts, but something is wrong with my setup/understanding. I can't see what is wrong. It is something simple with the setup that I'm missing.

When I load this index.html page in chrome, none of the script require.js action is working.

***index.html

<html>
<head>
   <title>My Sample Project</title>
</head>
<body>
   <h1 class="h1">sample project header</h1>
   <script data-main="main" src="require.js"></script>
</body>
</html>

***main.js

(function() {
  requirejs.config({
    //By default load any module IDs from baseUrl
    baseUrl: '',
    // paths config is relative to the baseUrl, and
    // never includes a ".js" extension 
    paths: {
      'small-blue-mod': './a-script'
    }
  });

  // Start the main app logic.
  requirejs(['small-blue-mod'], function (sbm) {
    alert(sbm.color);
  });
})();

***small-blue-mod.js

define({
   color: "blue",
   size: "small" 
});

*File System looks like...

index.html
main.js
require.js
FOLDER called "a-script"

a-script folder contains small-blue-mod.js

The path small-blue-mod refers to the a-script folder, either require it like small-blue-mod/small-blue-mod or recommended change your path to this:

paths: {
  'small-blue-mod': './a-script/small-blue-mod'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM