javascript - Require.js continues to load uncompressed modules after optimization -
i've run r.js optimizer , seems working properly. trouble i'm having while compressed optimized version loads continues load uncompressed modules. reason why happen?
build.js
{ appdir: '../static', mainconfigfile: '../static/javascript/config.js', dir: '../public', baseurl: 'javascript/libs', usestrict: false, wrap: false, optimizecss: "standard", optimize: "uglify2", generatesourcemaps: false, preservelicensecomments: false, uglify2: { "screw-ie8": true, warnings: false, mangle: true }, throwwhen: { optimize: true }, pragmasonsave: {}, modules: [ { name: '../front', include: ['views/front/main'], exclude: ['../config'] } , { name: '../portal', include: ['views/portal/main'], exclude: ['../config'] } , { name: '../survey', include: ['views/survey/main'], exclude: ['../config'] } ] }
config.js
require.config({ baseurl: '/javascript/libs', urlargs: 'v=' + (new date()).gettime(), enforcedefine: false, paths: { collections: '../collections', etc: '../etc', models: '../models', views: '../views', templates: '../../templates', backbone: 'backbone', underscore: 'lodash', 'underscore.string': 'underscore.string', }, shim: { backbone: { deps: ['jquery', 'underscore'], exports: 'backbone' }, underscore: { deps: ['jquery', 'underscore.string'], exports: '_' }, } });
the config loaded so:
<script data-main="/javascript/portal-v2.0.0.js" src="/javascript/libs/require.js"></script>
and portal.js looks this:
require(['./config'], function() { return require(['views/portal/main']); });
you start loading application this:
<script data-main="/javascript/portal-v2.0.0.js" src="/javascript/libs/require.js"></script>
what schedule loading of portal-v2.0.0.js
file. however, actual loading happens @ indeterminate point in future. (by way, should not put .js
@ end of module names. value of data-main
module name, no .js
there. can cause subtle problems.)
as evidenced loading patterns get, time following code executes, above module has not loaded:
require(['./config'], function() { return require(['views/portal/main']); });
when requirejs gets require(['views/portal/main'])
, finds , loads individual module instead of bundle.
the solution here add following runtime configuration:
bundles: { '/javascript/portal-v2.0.0': ['views/portal/main'], }
this tells requirejs when require module named views/portal/main
, should in same place module named /javascript/portal-v2.0.0
located. (and remember remove .js
extension data-main
.) not need list modules in portal-v2.0.0
there, requiring outside portal-v2.0.0
. note same true other bundles if of modules required outside of them, must list these modules in appropriate bundles
settings.
you should removecombined
remove individual files output directory , keep optimized bundles.
Comments
Post a Comment