Javascript not displaying - Brunch.io - brunch-with-brunch

元气小坏坏 提交于 2019-12-07 02:17:17

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18145790/javascript-not-displaying-brunch-io-brunch-with-brunch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!