6

I have just started a new brunch.io project using the brunch-with-brunch skeleton (I just want a local server able to display native HTML/CSS/JS).

I have created two files on my own : index.html located in public/ containing the standard doctype, head and body tags plus a script tag referencing the app.js generated by brunch located at public/javascripts/app.js as below :

<script type="text/javascript" src="javascripts/app.js"></script>

As specified by the README.md file located in the app/ directory, I write my applications-specific files in the app/ directory. So I have on file named app.js located in app/ and containing :

console.log("OK");

I start the server with the command :

brunch watch --server

The problem is that I don't see anything in the js console (the server is running at localhost:3333), despite the facts that the html is rendered and the public/javascripts/app.js (generated by brunch) contains these lines (among others) :

require.register("app", function(exports, require, module) {
    console.log("ok");
});

What's going on ?

EDIT : The javascript directly written in the html script tag works fine.

Simon
  • 1,679
  • 4
  • 21
  • 37

1 Answers1

9

Brunch wraps all files by default in module definitions (require.register). So, the console.log is not executed ASAP.

So, you will need to load the entry point in your index.html: <script>require('app')</script>

Module definitions can be disabled.

Paul Miller
  • 1,960
  • 1
  • 13
  • 15
  • 19
    For christ's-sake, could you PLEASE make that explicit in the documentation and include it in some sort of default skeleton? I was banging my head against this for hours yesterday. – Indolering Nov 29 '13 at 21:53
  • 1
    See the following post for how to disable the wrapping behavior: http://stackoverflow.com/questions/11074297/brunch-how-to-disable-requirejs-module-wrapping – k00k Feb 21 '14 at 19:35
  • Seriously, for figuring out why your javascript isn't running you have to find this post on stack overflow ? wow. I guess documentation really IS key when picking frameworks, innit ? what-the-frak hahaha http://brunch.io/docs/config#-modules- – Michahell Jun 15 '16 at 07:48
  • made an issue for this, its ridiculous : https://github.com/brunch/brunch/issues/1409 – Michahell Jun 15 '16 at 07:56