I installed requirejs nuget package and added to my Index.cshtml this:
<script src="~/lib/requirejs/require.js" data-main="/js/scripts/tetromino-client/client.js"></script>
My project structure looks like this:
wwwroot
|-js
|-scripts
|-tetromino-client
|-client.js
|-block.js
Views
|-Home
|-Index.cshtml
client.js
requirejs(["block"], function (Block) {
var block = new Block(); // Block is undefined
console.log(block.value);
});
block.js
function Block() {
this.value = 50;
}
Requirejs cannot resolve block.js and returns undefined. What did I do wrong?
Blockusing the RequireJSdefinesyntax?define()was similar torequirejs(). I found a solution.