问题
When following the general setup of example-multipage provided in the docs the common.js module seems to cause dependencies to make async XMLHttpRequest calls.
my directory structure is:
|-static
|-core
|-js
|-myApp.js
|-require.js
|-common.js
|-app.build.js
|-app
|-myApp.js
|-vendor
|-js
|-jquery.js
|-bootstrap.js
|-fancybox.js
contents of common.js:
require.config({
baseUrl: "/static/core/js",
paths: {
'jquery':'../../vendor/jquery/1.7.2/jquery',
'bootstrap':'../../vendor/bootstrap/2.2.2/js/bootstrap',
'fancybox':'../../vendor/fancybox/2.0.6/jquery.fancybox',
},
shim: {
'bootstrap':['jquery'],
'fancybox': ['jquery'],
'app/messages': ["jquery"],
},
waitSeconds: 12
});
contents of myApp.js
require(['common'], function (common) {
require(['app/myApp']);
});
Contents of app/myApp.js (YES I KNOW I AM POLLUTING THE GLOBAL NAMESPACE):
define(function (require) {
var $ = require('jquery');
require('fancybox');
require('app/messages');
//all my code here
});
My modules are defined as follows in app.build.js:
mainConfigFile: 'common.js',
removeCombined: true,
modules: [
{
name: 'common',
include: ['jquery', 'bootstrap']
},
{
name: 'myApp',
include: ['app/myApp'],
exclude: ['common']
},
],
When i REMOVE the common module from the build, everything works fine. I get one myApp.js file with all the dependencies combined into the one file (perfect!).
When i ADD the common module back in, the resulting js files are loaded: common.js(combined), myApp.js(combined), PLUS I ALSO GET myApp.js, common.js, bootstrap.js, fancybox.js, messages.js and nothing works.
One guess is that because i am creating paths to actual .js files in the require.config it is loading them as dependencies. Where if i only defined paths to directories this would not occur?
UPDATE: Since my common.js is shimmed, looks like i need to follow example-multipage-shim. Getting closer.
来源:https://stackoverflow.com/questions/22344539/requirejs-build-settings-for-a-common-js-module-along-with-a-main-js-module-whe