Javascript not showing up - Brunch.io - brunch s brunch

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

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

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

As indicated in the README.md file located in the app / directory, I write my application-specific files in the app / directory. Therefore, I have a file called app.js located in application / and containing:

 console.log("OK"); 

I start the server using the command:

 brunch watch --server 

The problem is that I do not see anything in the js console (the server runs on localhost: 3333), despite the fact that html is rendered, and public / javascripts / app.js (generated by brunch) contains these lines (among others) :

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

What's happening?

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

+6
source share
1 answer

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

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

Module definitions may be disabled.

+9
source

Source: https://habr.com/ru/post/951391/


All Articles