Skip to content

Instantly share code, notes, and snippets.

@codeithuman
Created March 31, 2016 17:51
Show Gist options
  • Save codeithuman/d8a4792779c6a6036af0acd3918b2a63 to your computer and use it in GitHub Desktop.
Save codeithuman/d8a4792779c6a6036af0acd3918b2a63 to your computer and use it in GitHub Desktop.
Issue with Phoenix and Brunch compiling multiple javascript files
// File structure
// web -> static -> js
// |-> contact -> contact.js
// |-> jquery -> accordion.js, navigation.js
// |-> registraiton -> registration.js
// |-> upcoming_classes -> upcoming_classes.js
// |-> app.js
// brunch-config.js files section
files: {
javascripts: {
joinTo: {
'js/app.js': /^web\/static\/js\/(?!registration)/,
'js/registration.js': /^web\/static\/js\/registration/
}
},
stylesheets: {
joinTo: 'css/app.css'
},
templates: {
joinTo: 'js/app.js'
}
},
// Beginning of compiled app.js and registration.js match. Where does it code come from?
(function() {
'use strict';
var globals = typeof window === 'undefined' ? global : window;
if (typeof globals.require === 'function') return;
var modules = {};
var cache = {};
var aliases = {};
var has = ({}).hasOwnProperty;
var unalias = function(alias, loaderPath) {
var result = aliases[alias] || aliases[alias + '/index.js'];
return result || alias;
};
var _reg = /^\.\.?(\/|$)/;
var expand = function(root, name) {
var results = [], part;
var parts = (_reg.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 module = {id: name, exports: {}};
cache[name] = module;
definition(module.exports, localRequire(name), module);
return module.exports;
};
var require = function(name, loaderPath) {
if (loaderPath == null) loaderPath = '/';
var path = unalias(name, loaderPath);
if (has.call(cache, path)) return cache[path].exports;
if (has.call(modules, path)) return initModule(path, modules[path]);
var dirIndex = expand(path, './index');
if (has.call(cache, dirIndex)) return cache[dirIndex].exports;
if (has.call(modules, dirIndex)) return initModule(dirIndex, modules[dirIndex]);
throw new Error('Cannot find module "' + name + '" from ' + '"' + loaderPath + '"');
};
require.alias = function(from, to) {
aliases[to] = from;
};
require.register = require.define = function(bundle, fn) {
if (typeof bundle === 'object') {
for (var key in bundle) {
if (has.call(bundle, key)) {
require.register(key, bundle[key]);
}
}
} else {
modules[bundle] = fn;
}
};
require.list = function() {
var result = [];
for (var item in modules) {
if (has.call(modules, item)) {
result.push(item);
}
}
return result;
};
require.brunch = true;
require._cache = cache;
globals.require = require;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment