External Js file generated by brunch is not working












1















I'm having trouble running external js from js file that is compiled by brunch.
My external js code is not invoked by the browser.
The external css compiled by brunch is fine though.



project structure:



+-- project_root
| +-- public
| +-- static
| +-- assets
| +-- css
| +-- main.css
| +-- js
| +-- main.js
| +-- templates
| +-- index.gohtml
| +-- brunch-config.js




my brunch-config.js:



module.exports = {
files: {
javascripts: {
joinTo: 'js/app.js'
},
stylesheets: {
joinTo: 'css/app.css'
}
},
paths: {
public: 'public',
watched: ['static']
},
plugins: {
cleancss: {
SpecialComments: 0,
removeEmpty: true
}
},
sourceMaps: false

};




simplified index.gohtml:



<html>
<head>
<link rel="stylesheet" href="public/css/app.css">
</head>
<body>
<p>content</p>
<script type="text/javascript" src="public/js/app.js"></script>
</body>
</html>




main.js:



alert("this is my external js file")




app.js generated by brunch while running brunch watch :



(function() {
'use strict';

var globals = typeof global === 'undefined' ? self : global;
if (typeof globals.require === 'function') return;

var modules = {};
var cache = {};
var aliases = {};
var has = {}.hasOwnProperty;

var expRe = /^..?(/|$)/;
var expand = function(root, name) {
var results = , part;
var parts = (expRe.test(name) ? root + '/' + name : name).split('/');
for (var i = 0, length = parts.length; i < length; i++) {
part = parts[i];
if (part === '..') {
results.pop();
} else if (part !== '.' && part !== '') {
results.push(part);
}
}
return results.join('/');
};

var dirname = function(path) {
return path.split('/').slice(0, -1).join('/');
};

var localRequire = function(path) {
return function expanded(name) {
var absolute = expand(dirname(path), name);
return globals.require(absolute, path);
};
};

var initModule = function(name, definition) {
var hot = hmr && hmr.createHot(name);
var module = {id: name, exports: {}, hot: hot};
cache[name] = module;
definition(module.exports, localRequire(name), module);
return module.exports;
};

var expandAlias = function(name) {
return aliases[name] ? expandAlias(aliases[name]) : name;
};

var _resolve = function(name, dep) {
return expandAlias(expand(dirname(name), dep));
};

var require = function(name, loaderPath) {
if (loaderPath == null) loaderPath = '/';
var path = expandAlias(name);

if (has.call(cache, path)) return cache[path].exports;
if (has.call(modules, path)) return initModule(path, modules[path]);

throw new Error("Cannot find module '" + name + "' from '" + loaderPath + "'");
};

require.alias = function(from, to) {
aliases[to] = from;
};

var extRe = /.[^./]+$/;
var indexRe = //index(.[^/]+)?$/;
var addExtensions = function(bundle) {
if (extRe.test(bundle)) {
var alias = bundle.replace(extRe, '');
if (!has.call(aliases, alias) || aliases[alias].replace(extRe, '') === alias + '/index') {
aliases[alias] = bundle;
}
}

if (indexRe.test(bundle)) {
var iAlias = bundle.replace(indexRe, '');
if (!has.call(aliases, iAlias)) {
aliases[iAlias] = bundle;
}
}
};

require.register = require.define = function(bundle, fn) {
if (bundle && typeof bundle === 'object') {
for (var key in bundle) {
if (has.call(bundle, key)) {
require.register(key, bundle[key]);
}
}
} else {
modules[bundle] = fn;
delete cache[bundle];
addExtensions(bundle);
}
};

require.list = function() {
var list = ;
for (var item in modules) {
if (has.call(modules, item)) {
list.push(item);
}
}
return list;
};

var hmr = globals._hmr && new globals._hmr(_resolve, require, modules, cache);
require._cache = cache;
require.hmr = hmr && hmr.wrap;
require.brunch = true;
globals.require = require;
})();

(function() {
var global = typeof window === 'undefined' ? this : window;
var __makeRelativeRequire = function(require, mappings, pref) {
var none = {};
var tryReq = function(name, pref) {
var val;
try {
val = require(pref + '/node_modules/' + name);
return val;
} catch (e) {
if (e.toString().indexOf('Cannot find module') === -1) {
throw e;
}

if (pref.indexOf('node_modules') !== -1) {
var s = pref.split('/');
var i = s.lastIndexOf('node_modules');
var newPref = s.slice(0, i).join('/');
return tryReq(name, newPref);
}
}
return none;
};
return function(name) {
if (name in mappings) name = mappings[name];
if (!name) return;
if (name[0] !== '.' && pref) {
var val = tryReq(name, pref);
if (val !== none) return val;
}
return require(name);
}
};
require.register("static/js/main.js", function(exports, require, module) {

alert("this is my external js");

});

;require.register("___globals___", function(exports, require, module) {

});})();require('___globals___');

/* jshint ignore:start */
(function() {
var WebSocket = window.WebSocket || window.MozWebSocket;
var br = window.brunch = (window.brunch || {});
var ar = br['auto-reload'] = (br['auto-reload'] || {});
if (!WebSocket || ar.disabled) return;
if (window._ar) return;
window._ar = true;

var cacheBuster = function(url){
var date = Math.round(Date.now() / 1000).toString();
url = url.replace(/(&|\?)cacheBuster=d*/, '');
return url + (url.indexOf('?') >= 0 ? '&' : '?') +'cacheBuster=' + date;
};

var browser = navigator.userAgent.toLowerCase();
var forceRepaint = ar.forceRepaint || browser.indexOf('chrome') > -1;

var reloaders = {
page: function(){
window.location.reload(true);
},

stylesheet: function(){
.slice
.call(document.querySelectorAll('link[rel=stylesheet]'))
.filter(function(link) {
var val = link.getAttribute('data-autoreload');
return link.href && val != 'false';
})
.forEach(function(link) {
link.href = cacheBuster(link.href);
});

// Hack to force page repaint after 25ms.
if (forceRepaint) setTimeout(function() { document.body.offsetHeight; }, 25);
},

javascript: function(){
var scripts = .slice.call(document.querySelectorAll('script'));
var textScripts = scripts.map(function(script) { return script.text }).filter(function(text) { return text.length > 0 });
var srcScripts = scripts.filter(function(script) { return script.src });

var loaded = 0;
var all = srcScripts.length;
var onLoad = function() {
loaded = loaded + 1;
if (loaded === all) {
textScripts.forEach(function(script) { eval(script); });
}
}

srcScripts
.forEach(function(script) {
var src = script.src;
script.remove();
var newScript = document.createElement('script');
newScript.src = cacheBuster(src);
newScript.async = true;
newScript.onload = onLoad;
document.head.appendChild(newScript);
});
}
};
var port = ar.port || 9486;
var host = br.server || window.location.hostname || 'localhost';

var connect = function(){
var connection = new WebSocket('ws://' + host + ':' + port);
connection.onmessage = function(event){
if (ar.disabled) return;
var message = event.data;
var reloader = reloaders[message] || reloaders.page;
reloader();
};
connection.onerror = function(){
if (connection.readyState) connection.close();
};
connection.onclose = function(){
window.setTimeout(connect, 1000);
};
};
connect();
})();
/* jshint ignore:end */

;


The app.js is automatically filled with additional js code that I don't understand as I'm not a js expert.



I have tried this:JS compiled by Brunch does not run still no luck.










share|improve this question



























    1















    I'm having trouble running external js from js file that is compiled by brunch.
    My external js code is not invoked by the browser.
    The external css compiled by brunch is fine though.



    project structure:



    +-- project_root
    | +-- public
    | +-- static
    | +-- assets
    | +-- css
    | +-- main.css
    | +-- js
    | +-- main.js
    | +-- templates
    | +-- index.gohtml
    | +-- brunch-config.js




    my brunch-config.js:



    module.exports = {
    files: {
    javascripts: {
    joinTo: 'js/app.js'
    },
    stylesheets: {
    joinTo: 'css/app.css'
    }
    },
    paths: {
    public: 'public',
    watched: ['static']
    },
    plugins: {
    cleancss: {
    SpecialComments: 0,
    removeEmpty: true
    }
    },
    sourceMaps: false

    };




    simplified index.gohtml:



    <html>
    <head>
    <link rel="stylesheet" href="public/css/app.css">
    </head>
    <body>
    <p>content</p>
    <script type="text/javascript" src="public/js/app.js"></script>
    </body>
    </html>




    main.js:



    alert("this is my external js file")




    app.js generated by brunch while running brunch watch :



    (function() {
    'use strict';

    var globals = typeof global === 'undefined' ? self : global;
    if (typeof globals.require === 'function') return;

    var modules = {};
    var cache = {};
    var aliases = {};
    var has = {}.hasOwnProperty;

    var expRe = /^..?(/|$)/;
    var expand = function(root, name) {
    var results = , part;
    var parts = (expRe.test(name) ? root + '/' + name : name).split('/');
    for (var i = 0, length = parts.length; i < length; i++) {
    part = parts[i];
    if (part === '..') {
    results.pop();
    } else if (part !== '.' && part !== '') {
    results.push(part);
    }
    }
    return results.join('/');
    };

    var dirname = function(path) {
    return path.split('/').slice(0, -1).join('/');
    };

    var localRequire = function(path) {
    return function expanded(name) {
    var absolute = expand(dirname(path), name);
    return globals.require(absolute, path);
    };
    };

    var initModule = function(name, definition) {
    var hot = hmr && hmr.createHot(name);
    var module = {id: name, exports: {}, hot: hot};
    cache[name] = module;
    definition(module.exports, localRequire(name), module);
    return module.exports;
    };

    var expandAlias = function(name) {
    return aliases[name] ? expandAlias(aliases[name]) : name;
    };

    var _resolve = function(name, dep) {
    return expandAlias(expand(dirname(name), dep));
    };

    var require = function(name, loaderPath) {
    if (loaderPath == null) loaderPath = '/';
    var path = expandAlias(name);

    if (has.call(cache, path)) return cache[path].exports;
    if (has.call(modules, path)) return initModule(path, modules[path]);

    throw new Error("Cannot find module '" + name + "' from '" + loaderPath + "'");
    };

    require.alias = function(from, to) {
    aliases[to] = from;
    };

    var extRe = /.[^./]+$/;
    var indexRe = //index(.[^/]+)?$/;
    var addExtensions = function(bundle) {
    if (extRe.test(bundle)) {
    var alias = bundle.replace(extRe, '');
    if (!has.call(aliases, alias) || aliases[alias].replace(extRe, '') === alias + '/index') {
    aliases[alias] = bundle;
    }
    }

    if (indexRe.test(bundle)) {
    var iAlias = bundle.replace(indexRe, '');
    if (!has.call(aliases, iAlias)) {
    aliases[iAlias] = bundle;
    }
    }
    };

    require.register = require.define = function(bundle, fn) {
    if (bundle && typeof bundle === 'object') {
    for (var key in bundle) {
    if (has.call(bundle, key)) {
    require.register(key, bundle[key]);
    }
    }
    } else {
    modules[bundle] = fn;
    delete cache[bundle];
    addExtensions(bundle);
    }
    };

    require.list = function() {
    var list = ;
    for (var item in modules) {
    if (has.call(modules, item)) {
    list.push(item);
    }
    }
    return list;
    };

    var hmr = globals._hmr && new globals._hmr(_resolve, require, modules, cache);
    require._cache = cache;
    require.hmr = hmr && hmr.wrap;
    require.brunch = true;
    globals.require = require;
    })();

    (function() {
    var global = typeof window === 'undefined' ? this : window;
    var __makeRelativeRequire = function(require, mappings, pref) {
    var none = {};
    var tryReq = function(name, pref) {
    var val;
    try {
    val = require(pref + '/node_modules/' + name);
    return val;
    } catch (e) {
    if (e.toString().indexOf('Cannot find module') === -1) {
    throw e;
    }

    if (pref.indexOf('node_modules') !== -1) {
    var s = pref.split('/');
    var i = s.lastIndexOf('node_modules');
    var newPref = s.slice(0, i).join('/');
    return tryReq(name, newPref);
    }
    }
    return none;
    };
    return function(name) {
    if (name in mappings) name = mappings[name];
    if (!name) return;
    if (name[0] !== '.' && pref) {
    var val = tryReq(name, pref);
    if (val !== none) return val;
    }
    return require(name);
    }
    };
    require.register("static/js/main.js", function(exports, require, module) {

    alert("this is my external js");

    });

    ;require.register("___globals___", function(exports, require, module) {

    });})();require('___globals___');

    /* jshint ignore:start */
    (function() {
    var WebSocket = window.WebSocket || window.MozWebSocket;
    var br = window.brunch = (window.brunch || {});
    var ar = br['auto-reload'] = (br['auto-reload'] || {});
    if (!WebSocket || ar.disabled) return;
    if (window._ar) return;
    window._ar = true;

    var cacheBuster = function(url){
    var date = Math.round(Date.now() / 1000).toString();
    url = url.replace(/(&|\?)cacheBuster=d*/, '');
    return url + (url.indexOf('?') >= 0 ? '&' : '?') +'cacheBuster=' + date;
    };

    var browser = navigator.userAgent.toLowerCase();
    var forceRepaint = ar.forceRepaint || browser.indexOf('chrome') > -1;

    var reloaders = {
    page: function(){
    window.location.reload(true);
    },

    stylesheet: function(){
    .slice
    .call(document.querySelectorAll('link[rel=stylesheet]'))
    .filter(function(link) {
    var val = link.getAttribute('data-autoreload');
    return link.href && val != 'false';
    })
    .forEach(function(link) {
    link.href = cacheBuster(link.href);
    });

    // Hack to force page repaint after 25ms.
    if (forceRepaint) setTimeout(function() { document.body.offsetHeight; }, 25);
    },

    javascript: function(){
    var scripts = .slice.call(document.querySelectorAll('script'));
    var textScripts = scripts.map(function(script) { return script.text }).filter(function(text) { return text.length > 0 });
    var srcScripts = scripts.filter(function(script) { return script.src });

    var loaded = 0;
    var all = srcScripts.length;
    var onLoad = function() {
    loaded = loaded + 1;
    if (loaded === all) {
    textScripts.forEach(function(script) { eval(script); });
    }
    }

    srcScripts
    .forEach(function(script) {
    var src = script.src;
    script.remove();
    var newScript = document.createElement('script');
    newScript.src = cacheBuster(src);
    newScript.async = true;
    newScript.onload = onLoad;
    document.head.appendChild(newScript);
    });
    }
    };
    var port = ar.port || 9486;
    var host = br.server || window.location.hostname || 'localhost';

    var connect = function(){
    var connection = new WebSocket('ws://' + host + ':' + port);
    connection.onmessage = function(event){
    if (ar.disabled) return;
    var message = event.data;
    var reloader = reloaders[message] || reloaders.page;
    reloader();
    };
    connection.onerror = function(){
    if (connection.readyState) connection.close();
    };
    connection.onclose = function(){
    window.setTimeout(connect, 1000);
    };
    };
    connect();
    })();
    /* jshint ignore:end */

    ;


    The app.js is automatically filled with additional js code that I don't understand as I'm not a js expert.



    I have tried this:JS compiled by Brunch does not run still no luck.










    share|improve this question

























      1












      1








      1








      I'm having trouble running external js from js file that is compiled by brunch.
      My external js code is not invoked by the browser.
      The external css compiled by brunch is fine though.



      project structure:



      +-- project_root
      | +-- public
      | +-- static
      | +-- assets
      | +-- css
      | +-- main.css
      | +-- js
      | +-- main.js
      | +-- templates
      | +-- index.gohtml
      | +-- brunch-config.js




      my brunch-config.js:



      module.exports = {
      files: {
      javascripts: {
      joinTo: 'js/app.js'
      },
      stylesheets: {
      joinTo: 'css/app.css'
      }
      },
      paths: {
      public: 'public',
      watched: ['static']
      },
      plugins: {
      cleancss: {
      SpecialComments: 0,
      removeEmpty: true
      }
      },
      sourceMaps: false

      };




      simplified index.gohtml:



      <html>
      <head>
      <link rel="stylesheet" href="public/css/app.css">
      </head>
      <body>
      <p>content</p>
      <script type="text/javascript" src="public/js/app.js"></script>
      </body>
      </html>




      main.js:



      alert("this is my external js file")




      app.js generated by brunch while running brunch watch :



      (function() {
      'use strict';

      var globals = typeof global === 'undefined' ? self : global;
      if (typeof globals.require === 'function') return;

      var modules = {};
      var cache = {};
      var aliases = {};
      var has = {}.hasOwnProperty;

      var expRe = /^..?(/|$)/;
      var expand = function(root, name) {
      var results = , part;
      var parts = (expRe.test(name) ? root + '/' + name : name).split('/');
      for (var i = 0, length = parts.length; i < length; i++) {
      part = parts[i];
      if (part === '..') {
      results.pop();
      } else if (part !== '.' && part !== '') {
      results.push(part);
      }
      }
      return results.join('/');
      };

      var dirname = function(path) {
      return path.split('/').slice(0, -1).join('/');
      };

      var localRequire = function(path) {
      return function expanded(name) {
      var absolute = expand(dirname(path), name);
      return globals.require(absolute, path);
      };
      };

      var initModule = function(name, definition) {
      var hot = hmr && hmr.createHot(name);
      var module = {id: name, exports: {}, hot: hot};
      cache[name] = module;
      definition(module.exports, localRequire(name), module);
      return module.exports;
      };

      var expandAlias = function(name) {
      return aliases[name] ? expandAlias(aliases[name]) : name;
      };

      var _resolve = function(name, dep) {
      return expandAlias(expand(dirname(name), dep));
      };

      var require = function(name, loaderPath) {
      if (loaderPath == null) loaderPath = '/';
      var path = expandAlias(name);

      if (has.call(cache, path)) return cache[path].exports;
      if (has.call(modules, path)) return initModule(path, modules[path]);

      throw new Error("Cannot find module '" + name + "' from '" + loaderPath + "'");
      };

      require.alias = function(from, to) {
      aliases[to] = from;
      };

      var extRe = /.[^./]+$/;
      var indexRe = //index(.[^/]+)?$/;
      var addExtensions = function(bundle) {
      if (extRe.test(bundle)) {
      var alias = bundle.replace(extRe, '');
      if (!has.call(aliases, alias) || aliases[alias].replace(extRe, '') === alias + '/index') {
      aliases[alias] = bundle;
      }
      }

      if (indexRe.test(bundle)) {
      var iAlias = bundle.replace(indexRe, '');
      if (!has.call(aliases, iAlias)) {
      aliases[iAlias] = bundle;
      }
      }
      };

      require.register = require.define = function(bundle, fn) {
      if (bundle && typeof bundle === 'object') {
      for (var key in bundle) {
      if (has.call(bundle, key)) {
      require.register(key, bundle[key]);
      }
      }
      } else {
      modules[bundle] = fn;
      delete cache[bundle];
      addExtensions(bundle);
      }
      };

      require.list = function() {
      var list = ;
      for (var item in modules) {
      if (has.call(modules, item)) {
      list.push(item);
      }
      }
      return list;
      };

      var hmr = globals._hmr && new globals._hmr(_resolve, require, modules, cache);
      require._cache = cache;
      require.hmr = hmr && hmr.wrap;
      require.brunch = true;
      globals.require = require;
      })();

      (function() {
      var global = typeof window === 'undefined' ? this : window;
      var __makeRelativeRequire = function(require, mappings, pref) {
      var none = {};
      var tryReq = function(name, pref) {
      var val;
      try {
      val = require(pref + '/node_modules/' + name);
      return val;
      } catch (e) {
      if (e.toString().indexOf('Cannot find module') === -1) {
      throw e;
      }

      if (pref.indexOf('node_modules') !== -1) {
      var s = pref.split('/');
      var i = s.lastIndexOf('node_modules');
      var newPref = s.slice(0, i).join('/');
      return tryReq(name, newPref);
      }
      }
      return none;
      };
      return function(name) {
      if (name in mappings) name = mappings[name];
      if (!name) return;
      if (name[0] !== '.' && pref) {
      var val = tryReq(name, pref);
      if (val !== none) return val;
      }
      return require(name);
      }
      };
      require.register("static/js/main.js", function(exports, require, module) {

      alert("this is my external js");

      });

      ;require.register("___globals___", function(exports, require, module) {

      });})();require('___globals___');

      /* jshint ignore:start */
      (function() {
      var WebSocket = window.WebSocket || window.MozWebSocket;
      var br = window.brunch = (window.brunch || {});
      var ar = br['auto-reload'] = (br['auto-reload'] || {});
      if (!WebSocket || ar.disabled) return;
      if (window._ar) return;
      window._ar = true;

      var cacheBuster = function(url){
      var date = Math.round(Date.now() / 1000).toString();
      url = url.replace(/(&|\?)cacheBuster=d*/, '');
      return url + (url.indexOf('?') >= 0 ? '&' : '?') +'cacheBuster=' + date;
      };

      var browser = navigator.userAgent.toLowerCase();
      var forceRepaint = ar.forceRepaint || browser.indexOf('chrome') > -1;

      var reloaders = {
      page: function(){
      window.location.reload(true);
      },

      stylesheet: function(){
      .slice
      .call(document.querySelectorAll('link[rel=stylesheet]'))
      .filter(function(link) {
      var val = link.getAttribute('data-autoreload');
      return link.href && val != 'false';
      })
      .forEach(function(link) {
      link.href = cacheBuster(link.href);
      });

      // Hack to force page repaint after 25ms.
      if (forceRepaint) setTimeout(function() { document.body.offsetHeight; }, 25);
      },

      javascript: function(){
      var scripts = .slice.call(document.querySelectorAll('script'));
      var textScripts = scripts.map(function(script) { return script.text }).filter(function(text) { return text.length > 0 });
      var srcScripts = scripts.filter(function(script) { return script.src });

      var loaded = 0;
      var all = srcScripts.length;
      var onLoad = function() {
      loaded = loaded + 1;
      if (loaded === all) {
      textScripts.forEach(function(script) { eval(script); });
      }
      }

      srcScripts
      .forEach(function(script) {
      var src = script.src;
      script.remove();
      var newScript = document.createElement('script');
      newScript.src = cacheBuster(src);
      newScript.async = true;
      newScript.onload = onLoad;
      document.head.appendChild(newScript);
      });
      }
      };
      var port = ar.port || 9486;
      var host = br.server || window.location.hostname || 'localhost';

      var connect = function(){
      var connection = new WebSocket('ws://' + host + ':' + port);
      connection.onmessage = function(event){
      if (ar.disabled) return;
      var message = event.data;
      var reloader = reloaders[message] || reloaders.page;
      reloader();
      };
      connection.onerror = function(){
      if (connection.readyState) connection.close();
      };
      connection.onclose = function(){
      window.setTimeout(connect, 1000);
      };
      };
      connect();
      })();
      /* jshint ignore:end */

      ;


      The app.js is automatically filled with additional js code that I don't understand as I'm not a js expert.



      I have tried this:JS compiled by Brunch does not run still no luck.










      share|improve this question














      I'm having trouble running external js from js file that is compiled by brunch.
      My external js code is not invoked by the browser.
      The external css compiled by brunch is fine though.



      project structure:



      +-- project_root
      | +-- public
      | +-- static
      | +-- assets
      | +-- css
      | +-- main.css
      | +-- js
      | +-- main.js
      | +-- templates
      | +-- index.gohtml
      | +-- brunch-config.js




      my brunch-config.js:



      module.exports = {
      files: {
      javascripts: {
      joinTo: 'js/app.js'
      },
      stylesheets: {
      joinTo: 'css/app.css'
      }
      },
      paths: {
      public: 'public',
      watched: ['static']
      },
      plugins: {
      cleancss: {
      SpecialComments: 0,
      removeEmpty: true
      }
      },
      sourceMaps: false

      };




      simplified index.gohtml:



      <html>
      <head>
      <link rel="stylesheet" href="public/css/app.css">
      </head>
      <body>
      <p>content</p>
      <script type="text/javascript" src="public/js/app.js"></script>
      </body>
      </html>




      main.js:



      alert("this is my external js file")




      app.js generated by brunch while running brunch watch :



      (function() {
      'use strict';

      var globals = typeof global === 'undefined' ? self : global;
      if (typeof globals.require === 'function') return;

      var modules = {};
      var cache = {};
      var aliases = {};
      var has = {}.hasOwnProperty;

      var expRe = /^..?(/|$)/;
      var expand = function(root, name) {
      var results = , part;
      var parts = (expRe.test(name) ? root + '/' + name : name).split('/');
      for (var i = 0, length = parts.length; i < length; i++) {
      part = parts[i];
      if (part === '..') {
      results.pop();
      } else if (part !== '.' && part !== '') {
      results.push(part);
      }
      }
      return results.join('/');
      };

      var dirname = function(path) {
      return path.split('/').slice(0, -1).join('/');
      };

      var localRequire = function(path) {
      return function expanded(name) {
      var absolute = expand(dirname(path), name);
      return globals.require(absolute, path);
      };
      };

      var initModule = function(name, definition) {
      var hot = hmr && hmr.createHot(name);
      var module = {id: name, exports: {}, hot: hot};
      cache[name] = module;
      definition(module.exports, localRequire(name), module);
      return module.exports;
      };

      var expandAlias = function(name) {
      return aliases[name] ? expandAlias(aliases[name]) : name;
      };

      var _resolve = function(name, dep) {
      return expandAlias(expand(dirname(name), dep));
      };

      var require = function(name, loaderPath) {
      if (loaderPath == null) loaderPath = '/';
      var path = expandAlias(name);

      if (has.call(cache, path)) return cache[path].exports;
      if (has.call(modules, path)) return initModule(path, modules[path]);

      throw new Error("Cannot find module '" + name + "' from '" + loaderPath + "'");
      };

      require.alias = function(from, to) {
      aliases[to] = from;
      };

      var extRe = /.[^./]+$/;
      var indexRe = //index(.[^/]+)?$/;
      var addExtensions = function(bundle) {
      if (extRe.test(bundle)) {
      var alias = bundle.replace(extRe, '');
      if (!has.call(aliases, alias) || aliases[alias].replace(extRe, '') === alias + '/index') {
      aliases[alias] = bundle;
      }
      }

      if (indexRe.test(bundle)) {
      var iAlias = bundle.replace(indexRe, '');
      if (!has.call(aliases, iAlias)) {
      aliases[iAlias] = bundle;
      }
      }
      };

      require.register = require.define = function(bundle, fn) {
      if (bundle && typeof bundle === 'object') {
      for (var key in bundle) {
      if (has.call(bundle, key)) {
      require.register(key, bundle[key]);
      }
      }
      } else {
      modules[bundle] = fn;
      delete cache[bundle];
      addExtensions(bundle);
      }
      };

      require.list = function() {
      var list = ;
      for (var item in modules) {
      if (has.call(modules, item)) {
      list.push(item);
      }
      }
      return list;
      };

      var hmr = globals._hmr && new globals._hmr(_resolve, require, modules, cache);
      require._cache = cache;
      require.hmr = hmr && hmr.wrap;
      require.brunch = true;
      globals.require = require;
      })();

      (function() {
      var global = typeof window === 'undefined' ? this : window;
      var __makeRelativeRequire = function(require, mappings, pref) {
      var none = {};
      var tryReq = function(name, pref) {
      var val;
      try {
      val = require(pref + '/node_modules/' + name);
      return val;
      } catch (e) {
      if (e.toString().indexOf('Cannot find module') === -1) {
      throw e;
      }

      if (pref.indexOf('node_modules') !== -1) {
      var s = pref.split('/');
      var i = s.lastIndexOf('node_modules');
      var newPref = s.slice(0, i).join('/');
      return tryReq(name, newPref);
      }
      }
      return none;
      };
      return function(name) {
      if (name in mappings) name = mappings[name];
      if (!name) return;
      if (name[0] !== '.' && pref) {
      var val = tryReq(name, pref);
      if (val !== none) return val;
      }
      return require(name);
      }
      };
      require.register("static/js/main.js", function(exports, require, module) {

      alert("this is my external js");

      });

      ;require.register("___globals___", function(exports, require, module) {

      });})();require('___globals___');

      /* jshint ignore:start */
      (function() {
      var WebSocket = window.WebSocket || window.MozWebSocket;
      var br = window.brunch = (window.brunch || {});
      var ar = br['auto-reload'] = (br['auto-reload'] || {});
      if (!WebSocket || ar.disabled) return;
      if (window._ar) return;
      window._ar = true;

      var cacheBuster = function(url){
      var date = Math.round(Date.now() / 1000).toString();
      url = url.replace(/(&|\?)cacheBuster=d*/, '');
      return url + (url.indexOf('?') >= 0 ? '&' : '?') +'cacheBuster=' + date;
      };

      var browser = navigator.userAgent.toLowerCase();
      var forceRepaint = ar.forceRepaint || browser.indexOf('chrome') > -1;

      var reloaders = {
      page: function(){
      window.location.reload(true);
      },

      stylesheet: function(){
      .slice
      .call(document.querySelectorAll('link[rel=stylesheet]'))
      .filter(function(link) {
      var val = link.getAttribute('data-autoreload');
      return link.href && val != 'false';
      })
      .forEach(function(link) {
      link.href = cacheBuster(link.href);
      });

      // Hack to force page repaint after 25ms.
      if (forceRepaint) setTimeout(function() { document.body.offsetHeight; }, 25);
      },

      javascript: function(){
      var scripts = .slice.call(document.querySelectorAll('script'));
      var textScripts = scripts.map(function(script) { return script.text }).filter(function(text) { return text.length > 0 });
      var srcScripts = scripts.filter(function(script) { return script.src });

      var loaded = 0;
      var all = srcScripts.length;
      var onLoad = function() {
      loaded = loaded + 1;
      if (loaded === all) {
      textScripts.forEach(function(script) { eval(script); });
      }
      }

      srcScripts
      .forEach(function(script) {
      var src = script.src;
      script.remove();
      var newScript = document.createElement('script');
      newScript.src = cacheBuster(src);
      newScript.async = true;
      newScript.onload = onLoad;
      document.head.appendChild(newScript);
      });
      }
      };
      var port = ar.port || 9486;
      var host = br.server || window.location.hostname || 'localhost';

      var connect = function(){
      var connection = new WebSocket('ws://' + host + ':' + port);
      connection.onmessage = function(event){
      if (ar.disabled) return;
      var message = event.data;
      var reloader = reloaders[message] || reloaders.page;
      reloader();
      };
      connection.onerror = function(){
      if (connection.readyState) connection.close();
      };
      connection.onclose = function(){
      window.setTimeout(connect, 1000);
      };
      };
      connect();
      })();
      /* jshint ignore:end */

      ;


      The app.js is automatically filled with additional js code that I don't understand as I'm not a js expert.



      I have tried this:JS compiled by Brunch does not run still no luck.







      javascript brunch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 8:10









      mhdmhd

      1,96282946




      1,96282946
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465727%2fexternal-js-file-generated-by-brunch-is-not-working%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465727%2fexternal-js-file-generated-by-brunch-is-not-working%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          To store a contact into the json file from server.js file using a class in NodeJS